Roblox Studio 管理员 GUI 设置玩家得分

嗨,我有点困惑,不知道如何通过管理员 GUI 设置玩家现金,我对这种语言不太熟悉,需要一些帮助。 这是 GUI 的样子

GUI 图片

Explorer 图片

代码图片

这是我到目前为止做的事情,不确定是否正确哈哈

button = script.Parent.MouseButton1Click:connect(function()
    local stat = Instance.new("IntValue")
    stat.Parent = script.Parent.Parent.casgplayertext.Text

    stat.Name = "Cash"
    stat.Value = script.Parent.Parent.cashetxt
    game.Players.childAdded:connect()
end)
点赞
用户9808476
用户9808476

统计数值应该是位于名为'leaderstats'的模型或文件夹对象中,位于玩家下(例如:Player1>leaderstats>Cash)。因此,您需要编写一个脚本来创建这个名为'leaderstats'的对象,并添加您想要的统计数据。这样,您将得到以下内容:

local players = game:WaitForChild("Players")

local function initializeLeaderstats(player)
    local stats = Instance.new("Folder")
    stats.Name = "leaderstats"
    local cashStat = Instance.new("IntValue", stats)
    cashStat.Name = "Cash"
    stats.Parent = player
end

players.PlayerAdded:connect(initializeLeaderstats)

然后您需要在另一个脚本中编写一些代码来操作某人的现金统计值。您可以编写一个函数,使用两个参数:玩家名称和现金金额。

local players = game:WaitForChild("Players")

local function setCashValue(playerName, value)
    local player = players:FindFirstChild(playerName)
    if player then
        local leaderStats = player.leaderstats
        local cashStat = leaderStats.Cash
        cashStat.Value = value
    end
end

当您单击“提交”按钮并输入两个参数(玩家名称和现金金额)时,您可以调用此函数。

2018-05-17 21:13:22