Hello, I am making a coin system where every time you complete a stage, you gain 2 coins. However, it only works one time. Whenever I complete a stage it gives 2 coins, but when I complete another stage it doesn’t give the coins but it says it does.
Can anyone help? Thanks, here is my code:
local plr = game.Players.LocalPlayer
local coinText = plr.PlayerGui.CoinSystem.Frame.TextLabel
local coinValue = tonumber(plr.PlayerGui.CoinSystem.Frame.TextLabel.Text)
local leaderstats = plr.leaderstats.Stage.Value
--local stageIn = 0
print('set locales')
for _, v in pairs(workspace.Checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent == plr.Character then
local stageNum = tonumber(v.Name)
print(plr.leaderstats.Stage.Value)
if stageNum < leaderstats or stageNum > leaderstats then
warn('person is less or more than their stage number')
return
else
print('Help me')
--if stageIn == 0 then
if stageNum < 20 and stageNum > 1 then --in easy
local newCoin = coinValue + 2
coinText.Text = tostring(newCoin) --add 2 coins
print('added easy coins')
--stageIn = stageNum
elseif stageNum < 40 and stageNum > 20 then --if in casual
coinText.Text = tostring(coinValue + 4)
--stageIn = stageNum
elseif stageNum < 51 and stageNum > 40 then --if in medium
coinText.Text = tostring(coinValue + 5)
--stageIn = stageNum
end
--elseif stageIn == stageNum then
-- print('stagein is equal to stagenum')
-- print(stageIn, stageNum.. "stageIn, stageNum")
-- return
--end
end
end
end)
end
No errors in the output, it prints “added easy coins”, but yet the coin value still stays at 2.