Coins Being Added [HELP!]

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! :smiley: 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

Where do you increment the plr.leaderstats.Stage.Value? Can you increment it in this script and if the players stage is less than this stage, increment the players stage to this one and reward the coins? This would only work if your stages are consecutive, otherwise you’d need to keep track of what stages the player has achieved.

1 Like

I am not incrementing the players stage value in leaderstats. The coins are a text label in startergui. I just want to make it so that when a player touches a checkpoint, the coins are added and the player can’t walk over it again and get the coins again. The stages are consecutive (1, 2, 3, 4…) and there is a stage value in leaderstats keeping track of the players stage number.

I’m not sure I understand what you are saying, your first sentence says you are not incrementing the players stage value in leaderstats yet your last sentence says there is a stage value in leaderstats keeping track of the players stage number.

Sorry for the confusion :sweat_smile:. I meant that I am not incrementing the stage value in the local script I provided in the original post. Were you asking what script handles it? If so, there is a server script in SSS handling the leaderstats.

So why don’t you just add the player coins in the server script when you increment the stage number in leaderstats?

1 Like

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