I’m trying to make it so if you touch a checkpoint less than or equal to stage then it will get the current value for the level transfer and will change the SpawnPoint to that. The SpawnPoint value acts as a previous checkpoint holder which will teleport you there instead of at your current stage just incase you want to go back and help someone, etc. However it isn’t meeting line 11 and 12 even though I’m going back a few levels and touching another checkpoint which should then change the value of that checpoint to the SpawnPoint. Also the Stage acts as your farthest level (and it’s not printing did).
The script:
local checkpoints = workspace:WaitForChild("Checkpoints")
for i,v in pairs(checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if tonumber(v.Name) == player.leaderstats.Stage.Value + 1 then --Checks if the new checkpoint is only increasing by 1.
player.leaderstats.Stage.Value = tonumber(v.Name)
if tonumber(v.Name) <= player.leaderstats.Stage.Value then
player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name)
print("did")
end
end
end
end)
end
end
1 Like
Could you explain what this line does:
player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name)
I don’t really understand why you have an = and a == sign on the same line.
1 Like
It’s suppose to make the current value equal to the SpawnPoint value (the SpawnPoint value is a temporary value which spawns them there if they die but it isn’t there actual stage)
Why did you use = and a ==? = is used to set a value, while == is used to compare values. I don’t really understand why you used both in the same line.
I thought they would set the value of the tostring to the values I already tried to make equal too. I think that was my bad because I didn’t know you couldn’t do that.
What kind of value is Current? Is Current a BoolValue?
Yes it is, as well as the SpawnPoint Value.
Can you try printing tonumber(v.Name) <= player.leaderstats.Stage.Value outside the if statement?
I did this and it underlines <=
local checkpoints = workspace:WaitForChild("Checkpoints")
for i,v in pairs(checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if tonumber(v.Name) == player.leaderstats.Stage.Value + 1 then -- Checks if the new checkpoint is only increasing by 1.
player.leaderstats.Stage.Value = tonumber(v.Name)
tonumber(v.Name) <= player.leaderstats.Stage.Value
print("did")
player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name)
end
end
end
end)
end
end
I meant doing print(tonumber(v.Name) <= player.leaderstats.Stage.Value), and you should print it outside the if statement.
1 Like
When I did that, it prints true.
Never mind, your issue was with how you structured your if statements. You put the if statement that checked if the player went back a level inside the if statement that checked if the player advanced a level.
I fixed that for you by using an elseif instead. Your code should look like this:
if tonumber(v.Name) == player.leaderstats.Stage.Value + 1 then --Checks if the new checkpoint is only increasing by 1.
player.leaderstats.Stage.Value = tonumber(v.Name)
elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name)
end
Problem is that it should change the SpawnPoint value when the current value changes.
I actually changed it back because I see what you mean now, although when I go back a few stages it doesn’t spawn me back there if I die.
local checkpoints = workspace:WaitForChild("Checkpoints")
for i,v in pairs(checkpoints:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if tonumber(v.Name) == player.leaderstats.Stage.Value + 1 then --Checks if the new checkpoint is only increasing by 1.
player.leaderstats.Stage.Value = tonumber(v.Name)
elseif tonumber(v.Name) <= player.leaderstats.Stage.Value then
print("test")
player.PlayerGui.Level.Current.Value = player.hidden.SpawnPoint.Value == tonumber(v.Name)
end
end
end)
end
end