Stage selector issue

I’m trying to create a stage selector for my obby where players can go back stages if they would like. However, my issue is that the GUI does not update when the player reaches a new stage.

[view comments below to see what is/isn’t working]

local LocalPlayer = game.Players.LocalPlayer

 -- this part works
while wait() do
	script.Parent.CurrentStage.Text = LocalPlayer.TeleportedStage.Value
end

-- this part does NOT work; text does not change
while wait() do 
	LocalPlayer.leaderstats.Stage.Value.Changed:Connect(function()
		LocalPlayer.TeleportedStage.Value = LocalPlayer.TeleportedStage.Value + 1
		LocalPlayer.TeleportedStage.Value = LocalPlayer.leaderstats.Stage.Value
	end)
end

TeleportedStage is the value that is displayed on the GUI. When a player reaches a new stage, it should add +1 to the value, which changes the GUI as well. However it does not change the GUI.

Any help is appreciated; thanks!

1 Like

The first loop is non-terminating because of a hack. Therefore code under it won’t get to execute.

You will want to listen for the Changed event here anyway; you were really close to doing that correctly in the second loop.

local Players = game:GetService("Players") -- obtain all services using game:GetService
local LocalPlayer = Players.LocalPlayer

local leaderstats = LocalPlayer:WaitForChild("leaderstats")
local Stage = leaderstats:WaitForChild("Stage")

local TeleportedStage = LocalPlayer:WaitForChild("TeleportedStage")
local CurrentStageLabel = script.Parent:WaitForChild("CurrentStage")

TeleportedStage.Changed:Connect(function(new)
	script.Parent.CurrentStage.Text = new
end)

Stage.Value.Changed:Connect(function()
    LocalPlayer.TeleportedStage.Value = Stage.Value
end)
1 Like

Script looks fine but it still didn’t change the text and I keep on getting this error for some reason

Stage.Value.Changed:Connect(function()

Stage.Value.Changed:Connect(function()
    LocalPlayer.TeleportedStage.Value = Stage.Value
end)

It shouldn’t be Value.Changed , you gotta check if the the Instance Changed or do

Stage:GetPropertyChangedSignal('Value'):Connect(function()

this detects when Value is Changed.

1 Like

Thanks for your help! Also thank you @sjr04 for the guidance.

1 Like

Actually this is unnecessary, since ValueBase instances use a non-inherited Changed event which only fires when the Value property changes, and the event listeners for it get the new Value as an argument.

1 Like

I was just explaining How GetPropertyChangedSignal works so he could use it in the future to detect changing of properties. But what you made is a good point too ! :smile:

1 Like

I have another issue - for some reason when you click the arrows the TeleportedStage value gets stuck at 99 and you have to rejoin for it to work again. Is there something wrong?

Would you show the Code where you Click the Button and Change its text?

local back = script.Parent:WaitForChild("CurrentStage"):FindFirstChild("Back")
local forw = script.Parent:WaitForChild("CurrentStage"):FindFirstChild("Forward")
local chartorso = LocalPlayer.Character:WaitForChild("Torso")

forw.MouseButton1Click:Connect(function()
	if LocalPlayer.TeleportedStage.Value < Stage.Value then
		LocalPlayer.TeleportedStage.Value = LocalPlayer.TeleportedStage.Value + 1
		chartorso.CFrame = CFrame.new(workspace.TelePoints[TeleportedStage.Value].Position)
	end
end)

back.MouseButton1Click:Connect(function()
	if LocalPlayer.TeleportedStage.Value <= Stage.Value then
		LocalPlayer.TeleportedStage.Value = LocalPlayer.TeleportedStage.Value - 1
		chartorso.CFrame = CFrame.new(workspace.TelePoints[TeleportedStage.Value].Position)
	end
end)

The issue is with your If conditions I assume . I guess your LocalPlayer.TeleportedStage.Value will be 100 , so when your Stage.Value Becomes 99
100 <= or < 99 wont work , so do
if LocalPlayer.TeleportedStage.Value > Stage.Value
This should work .

1 Like

It’s odd because now if you click back you can’t go forward since it checks if TeleportedStage is greater than Stage.

Well try removing the if condition where you reduce the Stage.Value , that is not really needed and replace it with if 0 < Stage.Value This Prevents it going below 0.

first u do the math then do the science and u get the fix to ur script