Hello! I am making an obby game and I want the player to gain 2 coins every time they complete a stage. This works, however, it adds the coins when you walk over it so you can get infinite coins. I want it to add the coins then when the player walks over it they can’t get the coins again.
Can someone help? I don’t know how to do this; you don’t have to write me an entire script just give me some pointers on how to do it. I would really appreciate it! Here is my script.
Many thanks!
local plr = game.Players.LocalPlayer
local coinText = plr.PlayerGui.CoinSystem.Frame.TextLabel
for _, v in pairs(workspace.Checkpoints:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Parent == plr.Character then
local stageNum = tonumber(v.Name)
local leaderstats = plr.leaderstats.Stage.Value
local coinValue = tonumber(plr.PlayerGui.CoinSystem.Frame.TextLabel.Text)
print(plr.leaderstats.Stage.Value)
task.wait(0.001)
if stageNum < leaderstats then
warn('person is less than their stage number')
return
else
print('Help me')
if stageNum < 20 and stageNum > 1 then --in easy
local newCoin = coinValue + 2
coinText.Text = tostring(newCoin) --add 2 coins
elseif stageNum < 40 and stageNum > 20 then --if in casual
local newCoin = coinValue + 4
coinText.Text = tostring(newCoin)
elseif stageNum < 51 and stageNum > 40 then --if in medium
local newCoin = coinValue + 5
coinText.Text = tostring(newCoin)
end
--elseif stageIn == stageNum then
-- print('stagein is equal to stagenum')
-- print(stageIn, stageNum.. "stageIn, stageNum")
-- return
--end
end
end
end)
end