Value being incorrectly displayed & given

So I’m basically trying to make money flow / income in Studio, and I faced a problem where:
image
This (upper screenshot) is setting amount of income to 10, since it’s by default 0
And these screenshots display how the money is received and/or given, yes it’s not anti-exploiter protected nor smart, I’m only experimenting.
image
image

My issue is, that even if the amount is 10 or above, it still gives 0 to player. I searched in devforum for the solution, but I haven’t found any solution so far, I only found random old’ish post that isn’t relevant to my problem.

image
( this screenshot shows how much I receive, probably same as in real life. )

So far, I have no clue how to fix it and make so that it’ll give me the IncomeAmount value instead of 0
Fun fact, when I set IncomeAmount anything above 0, it gives me the amount I set. I don’t know why while true do doesn’t even determine if the amount is changed.
Maybe I should add conds.IncomeAmount:GetPropertyChangedSignal(), but I think it won’t really do anything.

1 Like

You are reusing the first value of conditions.IncomeAmount as you’ve assigned it as the value of a variable outside of the function.
Instead, try doing something like:

events.DataReceive.OnServerEvent:Connect(function(player)
    local income = conditions.IncomeAmount.Value
    if income == 0 then
        conditions.IncomeAmount.Value += 10
    else
        player.leaderstats.Cash.Value += income
    end
end)

Also, I don’t really understand the point of wait(5) under the if statement. Is that supposed to be a debounce?

1 Like

Hello, thanks.

Your response helped me to understand how it works and why my didn’t work, also,

I use it as income per 5 seconds for now, but later I’ll transform it in smarter way of receiving income.

Thanks a lot for letting me know how to fix my issue!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.