为什么这个 Int Value 设置后一直在返回呢? [Roblox 工作室]

Why does this Int Value keep coming back after it is set? [Roblox Studio]

如果这是一个非常简单或容易的问题,我很抱歉,但我试图将玩家 leaderstat“Money”设置为 0,但它一直作为旧值返回。我能想到的唯一可能导致此问题的是 moneyGain 脚本正在重复。

这是我的 moneyGain 脚本:

local playerMoney

while wait(0.24) do
    local buttons = script.Parent.Parent.info.savedItems.Value.buttons:GetChildren()
    for button = 1, #buttons, 1 do
        if buttons[button].Parent.Parent.tycoon.Value ~= nil then
            if buttons[button].Parent.Parent.tycoon.Value.info.owner ~= nil then
                if buttons[button].jobDone.Value == true then
                    script.Parent.moneyEnforcer.enforce:Invoke(buttons[button].gainVal.Value)
                end
            end
        end
    end
    
    --OWNERDOOR:
    if script.Parent.Parent.info.owner.Value ~= nil then
        script.Parent.moneyEnforcer.enforce:Invoke(1)
    end
end

这是我的 moneyEnforcer 脚本:

local rs = game:GetService("ReplicatedStorage")
local dictionary = require(rs.dictionary)
local vipPlayers = dictionary.vipPlayers

script.enforce.OnInvoke = function(amount)
    print(amount)
    if script.Parent.Parent.info.player.Value ~= nil then
        if game:GetService("GamePassService"):PlayerHasPass(script.Parent.Parent.info.player.Value, 25494219) then
            amount = amount * 2
        else
            for i = 1, #vipPlayers, 1 do
                if script.Parent.Parent.info.player.Value.Name == vipPlayers[i] then
                    amount = amount * 2
                end
            end
        end
        local playerMoney = script.Parent.Parent.info.player.Value.leaderstats.Money
        script.Parent.Parent.info.player.Value.leaderstats.Money.Value = script.Parent.Parent.info.player.Value.leaderstats.Money.Value + amount
    end
end

这里是大亨重置器:

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
script.Parent.Parent.Parent.Visible = false

script.Parent.MouseButton1Click:Connect(function()
    player.leaderstats.Money.Value = 0
    script.Parent.Parent.Parent.Visible = false
    local savedItems = player.claimedTycoon.Value.info.savedItems.Value
    local builds = player.claimedTycoon.Value.activeBuilds:GetChildren()
    local buttons = player.claimedTycoon.Value.activeButtons:GetChildren()
    for i = 1, #builds, 1 do
        builds[i].Parent = savedItems.builds
    end
    for j = 1, #buttons, 1 do
        buttons[j].Parent = savedItems.buttons
    end
    savedItems.builds.dirtStarterBase.Parent = player.claimedTycoon.Value
    player.claimedTycoon.Value.info:WaitForChild("activeWave").Value = 1
end)

我试过将“script.Parent.Parent.info.player.Value.leaderstats.Money.Value = script.Parent.Parent.info.player.Value.leaderstats.Money.Value + amount”放在 moneyGain 脚本上,但没有任何区别。

欢迎任何帮助!

我认为您的问题是您正在从客户端设置金钱的价值当您从本地脚本更改该值时,它不会在服务器上更新.要解决此问题,更新服务器的值

tycoon reseter 中,尝试使用 RemoteEvent

从服务器重置值