Need to chance my detect and update my variable when value chances

So im making thsi script that makes it so you can tp to other stages u have already onlucked, all works well but i need to make it so my variable chances otherwise it hangs at (for example) 40, ve tried some stuff like GetPropertyChangedSignal but that gives me an error: attempt to index number with ‘GetPropertyChangedSignal’ , anyone have any ideas?

local checkpoints = workspace:WaitForChild("Checkpoints")
local stagenumgui = game.StarterGui.ScreenGui.TextLabel

game.Players.PlayerAdded:Connect(function(plr)
	local stagenum = plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value
	stagenum:GetPropertyChangedSignal(plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value):connect(function()
	local secondstagenum = stagenum + 1
game.ReplicatedStorage.GoBack.OnServerEvent:Connect(function()
	stagenum -= 1
	plr.Character:MoveTo(checkpoints[stagenum].Position)
	game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum))
end)

game.ReplicatedStorage.GoForeward.OnServerEvent:Connect(function()
	if secondstagenum ~= stagenum + 1 then
	stagenum += 1
	plr.Character:MoveTo(checkpoints[stagenum].Position)
	game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum))
	end
end)
end)
end)

on this line:
local stagenum = plr:WaitForChild(“leaderstats”):WaitForChild(“Stage”).Value
replace it to
local stagenum = plr:WaitForChild(“leaderstats”):WaitForChild(“Stage”)
and replace
stagenum:GetPropertyChangedSignal(plr:WaitForChild(“leaderstats”):WaitForChild(“Stage”).Value):connect(function() to stagenum:GetPropertyChangedSignal(“Value”):connect(function()

You use GetPropertyChangedSignal on the actual thing. So, it would be:

local var = plr:WaitForChild("leaderstats"):WaitForChild("Stage")

stage:GetPropertyChangedSignal("Value"):Connect(function() --[[etc.]] end)

edit: the person above me took it…

Also, it looks like when one client fires the remote it will move all clients forward/back. You need to make it only happen for that player.

thx il try it out and see if it works il let you know in about 5 mins

1 Like

ok so it kinda works, i chanced the script up a bit but now if i switch between unlocked stages my leaderstat also chances so i need to fix that + the checkpoints are also bugged so i cant unlock the next one

local checkpoints = workspace:WaitForChild("Checkpoints")
local stagenumgui = game.StarterGui.ScreenGui.TextLabel


game.Players.PlayerAdded:Connect(function(plr)
   local stagenum = plr:WaitForChild("leaderstats"):WaitForChild("Stage")
   stagenum:GetPropertyChangedSignal("Value"):connect(function()
   	stagenum = plr:WaitForChild("leaderstats"):WaitForChild("Stage")
   end)
   
   local secondstagenum = stagenum.Value + 1
game.ReplicatedStorage.GoBack.OnServerEvent:Connect(function()
   stagenum.Value -= 1
   plr.Character:MoveTo(checkpoints[stagenum.Value].Position)
   game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum.Value))
end)

game.ReplicatedStorage.GoForeward.OnServerEvent:Connect(function()
   if secondstagenum ~= stagenum.Value + 1 then
   	stagenum.Value += 1
   	plr.Character:MoveTo(checkpoints[stagenum.Value].Position)
   	game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum.Value))
   end
end)
end)

alr i made some fixes and it almost works but can u help me since sometimes it overshoots the if secondstagenum ~= stagenum2 + 1 then and it just completely ignores it even though the checkpoints do count rn

local checkpoints = workspace:WaitForChild("Checkpoints")
local stagenumgui = game.StarterGui.ScreenGui.TextLabel


game.Players.PlayerAdded:Connect(function(plr)
	local stagenum = plr:WaitForChild("leaderstats"):WaitForChild("Stage")
	local stagenum2 = plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value
	stagenum:GetPropertyChangedSignal("Value"):connect(function()
		stagenum2 = plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value
	end)
	
	local secondstagenum = stagenum2 + 1
game.ReplicatedStorage.GoBack.OnServerEvent:Connect(function()
	stagenum2 -= 1
	plr.Character:MoveTo(checkpoints[stagenum2].Position)
	game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum2))
end)

game.ReplicatedStorage.GoForeward.OnServerEvent:Connect(function()
	if secondstagenum ~= stagenum2 + 1 then
	stagenum2 += 1
	plr.Character:MoveTo(checkpoints[stagenum2].Position)
	game.ReplicatedStorage.GoBack:FireClient(plr, tostring(stagenum2))
	end
end)
end)