简体   繁体   中英

Roblox money distribution system not working

enter image description here I was trying to make a money collection system for the person on the stone grey team, but it won't work. What it should do is take the wealth value from the province, multiply by 0.02 and add that onto the total amount of money for the person. The leaderboard has the 'Finances' on there, but the value stays at 0 no matter what. The output bar is also blank.

local map = game.Workspace.map
local rp = game:GetService("ReplicatedStorage")

local provinces = {
    map.province1,
    map.province2,
    map.province3,
    map.province4,
    map.province5,
    map.province6,
    map.province7,
    map.province8,
    map.province9
}

game.Players.PlayerAdded:Connect(function(plr)
    local stats = Instance.new("BoolValue")
    stats.Name = "leaderstats"
    stats.Parent = plr
    local finances = Instance.new("NumberValue")
    finances.Name = "Finances"
    finances.Parent = plr.leaderstats
end)

-- below here i have problems, above this seems to work normally

rp.TaxPaymentsCheque.OnServerEvent:Connect(function(plr)
    for start = 1, #provinces  do
        local provincegrowing = provinces[start]
        if provincegrowing.BrickColor == BrickColor.new("Dark stone grey") then
            local finances = plr.leaderstats.Finances.Value
            local wealth = provincegrowing.ProvinceWealth.Value
            local taxmodifier = 0.02
            local revenue = wealth * taxmodifier
            local oldfinanceamount = finances
            finances = oldfinanceamount + revenue
        end
    end
end) 

There is also a picture if it can be of any use.

So the reason why you don't see any change is because you're not actually changing the Finances Value

Instead what you are doing is saving Finances' Value to a variable and changing the variable

local number = SomeIntValue.Value
number = number * 5
-- is practically the same as saying
local number = 1
number = number * 5

It doesn't actually set the IntValue's value To do that, do something like this

local number = SomeIntValue.Value
number = number * 5
SomeIntValue.Value = number
-- or
SomeIntValue.Value = SomeIntValue.Value * 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM