UI not changing to the correct value

I made a teleportation transfer system and weirdly enough it transfers me to my current stage and then it transfers me to the other stages perfectly as shown in the video:

I don’t know why it perfectly transfer me afterwards but not at first here are a few scripts which could be causing this issue. I’m pretty sure this is what’s causing it Level.Text = CurrentValue.Value the text value is the GUI that changes when the current value changes. Let me know if you need to know what something is or more information because I’ll gladly provide it to you with what I know!

The GUI handler:

local UI = script.Parent

local player = game.Players.LocalPlayer

local checkpoints = workspace:WaitForChild("Checkpoints")

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = ReplicatedStorage:WaitForChild("Teleport")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")

local Counter = UI:WaitForChild("Counter")
local Level = Counter:WaitForChild("Level")
local Previous = UI:WaitForChild("Previous")
local Next = UI:WaitForChild("Next")
local Previous1 = UI:WaitForChild("Previous1")
local Next1 = UI:WaitForChild("Next1")
local CurrentValue = UI:WaitForChild("Current")

local function previousLevel()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value ~= 1 then
		Level.Text = CurrentValue.Value
		print("sent back 1 level")
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function previousLevel2()
	script.Parent.Handler.Click:Play()
	if CurrentValue.Value >= 11 then
		Level.Text = CurrentValue.Value
		print("sent back 10 levels")
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 1) <= player.leaderstats.Stage.Value then
		Level.Text = CurrentValue.Value
		print("sent forward 1 level")
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end

local function nextLevel2()
	script.Parent.Handler.Click:Play()
	if (CurrentValue.Value + 10) <= player.leaderstats.Stage.Value then
		Level.Text = CurrentValue.Value
		print("sent forward 10 levels")
		-- teleport
		Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))
	end
end


Previous.MouseButton1Click:Connect(function()
	previousLevel()
	remoteEvent:FireServer("updateCurrent", player.PlayerGui.Level.Current.Value - 1)
	remoteEvent:FireServer("updateSpawnPoint", player.hidden.SpawnPoint.Value - 1)
end)

Previous1.MouseButton1Click:Connect(function()
	previousLevel2()
	remoteEvent:FireServer("updateCurrent", player.PlayerGui.Level.Current.Value - 10)
	remoteEvent:FireServer("updateSpawnPoint", player.hidden.SpawnPoint.Value - 10)
end)

Next.MouseButton1Click:Connect(function()
	nextLevel()
	remoteEvent:FireServer("updateCurrent", player.PlayerGui.Level.Current.Value + 1)
	remoteEvent:FireServer("updateSpawnPoint", player.hidden.SpawnPoint.Value + 1)
end)

Next1.MouseButton1Click:Connect(function()
	nextLevel2()
	remoteEvent:FireServer("updateCurrent", player.PlayerGui.Level.Current.Value + 10)
	remoteEvent:FireServer("updateSpawnPoint", player.hidden.SpawnPoint.Value + 10)
end)

CurrentValue.Value = player:WaitForChild("leaderstats").Stage.Value
Level.Text = CurrentValue.Value

player.leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
	CurrentValue.Value = player.leaderstats.Stage.Value
	Level.Text = CurrentValue.Value
end)

Remote Event script:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("remoteEvent")

remoteEvent.OnServerEvent:Connect(function(plr, job, msg)
	if job == "updateCurrent" then
		print("updated current")
		plr.PlayerGui.Level.Current.Value = msg
	end
	if job == "updateSpawnPoint" then
		print("updated spawnpoint")
		plr.hidden.SpawnPoint.Value = msg
	end
end)
1 Like

From what I see you’re updating CurrentValue only after you teleport the player.

You’re calling the previousLevel function which takes CurrentValue, check if It isn’t 1 and teleports the player, only after that it updates -1 to CurrentValue.

So It makes sense to work after that, since now the CurrentValue is correctly -1, and when you call the function it will teleport you -1 correctly, and it will only after that again give -1 to CurrentValue.

Maybe try calling the function after you update CurrentValue.

Previous.MouseButton1Click:Connect(function()
    remoteEvent:FireServer("updateCurrent", player.PlayerGui.Level.Current.Value - 1)
	remoteEvent:FireServer("updateSpawnPoint", player.hidden.SpawnPoint.Value - 1)
	previousLevel()
end)

(This is for all the functions not only previousLevel)

1 Like

Hmm, that’s weird, I just changed that and it’s still occurring like the video. (And yes I’ve changed them for all)

Please check if CurrentValue isn’t actually 7 when you call the function.

Try to change

Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value)))

to:

Teleport:FireServer(checkpoints:FindFirstChild(tostring(CurrentValue.Value -1)))

and see if it’ll affect anything.

1 Like

This is what happens: (Very close just the text doesn’t match the actual stage)

Then it seems to be working, you’re getting teleported to the previous stage.

The text isn’t changing because you need to change

Level.Text = CurrentValue.Value

to

Level.Text = CurrentValue.Value -1

Besides that check if everything is alright, such as getting into level 1 and etc.

That didn’t seem to work, I also tried Level.Text = Level.Text - 1 and that didn’t work either.

That’s interesting, you mean the text is not changing right?

Can you put a print(CurrentValue) on the previousLevel function where the other print is so it prints what CurrentValue is? Also can you tell me if the checkpoint you were in this last video was the 7th one?

Instead of changing Level.Text in the function, try to change Level.Text in the last line:

player.leaderstats.Stage:GetPropertyChangedSignal("Value"):Connect(function()
	CurrentValue.Value = player.leaderstats.Stage.Value
	Level.Text = CurrentValue.Value -1
end)
1 Like

First question, It prints Current. Second question, the first checkpoint in that video was 7 and I tried that code and it didn’t work.

Yeah at this point I don’t really know what’s going on too, I see in your video that the Stage value in the leaderboard is not changing, so fixing that might help with it.

Don’t really know why the text is not changing correctly even after you’ve changed
Level.Text = CurrentValue.Value -1
since there should be a difference from the last time at least, is there anything else changing that text?

Why don’t you try using the changed function? You’d detect whatever instance had their value changed and have that be reflected into the ui

Not that I’m aware of, I don’t see it being changed anywhere else.

Never heard of a changed function, I’ll look into it.

I printed the value again, and it says 7 the first time I print it and then 6 and so on.

1 Like