在 LocalScript 中制作摘要 object (Roblox LUA)

Making an abstract object within a LocalScript (Roblox LUA)

我正在尝试为游戏添加货币系统。我添加了一个脚本,当 child 被添加到播放器时,该脚本在 LocalPlayer 内的 NumberValue 中给出 $2500。但是我不确定如何在脚本中创建 NumberValue 并且我不能使用 instance.new 因为 NumberValues 是抽象的。有什么想法吗?

编辑-这是我试过的一些代码,它克隆了一个 pre-existing NumberValue

function AddPlayer()
    local Money = script.Parent.Money
    local Clone = Money:Clone()
    Clone.Parent = game.Players.LocalPlayer   
    Clone.Value = 2500
    Clone.Name = "Money"
end

game.Players.ChildAdded:connect(AddPlayer)

我不知道你说的是什么意思NumberValues are "abstract" (clarify?). But there should be nothing that prevents you from creating it using Instance.new

local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Value = 2500

, you should be doing this on the server, and you should have FilteringEnabled.

基本上将普通脚本放入 "Game.ServerScriptService" 中,代码为:

game:GetService("Players").PlayerAdded:connect(function(player)
    local Money = Instance.new("NumberValue")
    Money.Name = "Money"
    Money.Value = 2500
    Money.Parent = player
end)

还要注意的是,你应该使用PlayerAdded and not ChildAdded, as PlayerAdded only triggers when a player is added, while ChildAdded also triggers if someone puts junk in Game.Players