Coin system! [HELP!]

Helloooo! I hope you’re having a good day.

Currently, I’m working on an obby game and when they complete a stage, they get coins. It depends on what difficulty they are in, though. If they are in easy they get 2 coins, if in medium 4 coins, hard 5 coins, etc.

It works however it only works when they leave and rejoin on a stage. For example, if a player spawns on stage 6, and completes stage 7, they don’t get the coins until they rejoin on stage 7.

I don’t know how to fix it and when they rejoin, the code after the print statement, print("Help me") does not run.

Here is my code, if anyone can help me that would be great and I would really appreciate it! :smiley:

local plr = game.Players.LocalPlayer
local coinText = plr.PlayerGui.CoinSystem.Frame.TextLabel
local coinValue = tonumber(plr.PlayerGui.CoinSystem.Frame.TextLabel.Text)
local stagetrans = plr.PlayerGui.StageTransfer.CurrentStage
local stageIn = 0
print('set locales')

for _, v in pairs(workspace.Checkpoints:GetChildren()) do
	print('for loop')
	v.Touched:Connect(function(hit)
		print('hitttttt')
		if hit.Parent == plr.Character then
			print('is a plrrrrrrr')
			local stageNum = tonumber(v.Name)
			task.wait(0.001) --wait for stagetrans to update
			print('waited')
			if stageNum < tonumber(plr.leaderstats.Stage.Value) then
				print('person is less than their stage numebr!')
				return
			else
				print('Help me')
				if stageIn == 0 then
					print('stage in is 0')
					if stageNum < 20 and stageNum > 1 then --in easy
						print('in ez')
						coinText.Text = tostring(coinValue + 2) --add 2 coins
						stageIn = stageNum
						print('added coins')
					elseif stageNum < 40 and stageNum > 20 then --if in casual
						coinText.Text = tostring(coinValue + 4)
						stageIn = stageNum
						print('in casual and added coins')
					elseif stageNum < 51 and stageNum > 40 then --if in medium
						coinText.Text = tostring(coinValue + 5)
						stageIn = stageNum
						print('in medium and add coins')
					end
					print('end of if statement o noe')
				elseif stageIn == stageNum then
					print('stagein is equal to stagenum')
					print(stageIn, stageNum.. "stageIn, stageNum")
					return
				end
			end
		end
	end)
end

Can you print tonumber(plr.leaderstats.Stage.Value) ?

I printed it here

task.wait(0.001) --wait for stagetrans to update
			print('waited')
			print(tonumber(plr.leaderstats.Stage.Value))
			if stageNum < tonumber(plr.leaderstats.Stage.Value) then
				print('person is less than their stage numebr!')
				return
			else

It changes everytime I complete a stage so it says 6 when I’m on stage 6 and 7 when I’m on stage 7.

1 Like

UPDATE:

It works now however it only adds coins for one stage and not the rest of the stages. I don’t know why.