What solutions have you tried so far? I have tried everything that I could find on DevForum but still, no progress.
Here are the scripts:
Left Button - Local Script:
local plr = game:GetService("Players").LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local left = script.Parent
local text = script.Parent.Parent.CheckpointsLabel
local checkpoints = game.Workspace.Checkpoints
left.MouseButton1Click:Connect(function()
local stage = game.Players.LocalPlayer.leaderstats.Stage
if tonumber(text.Text) == 0 then
text.Text = stage.Value + 1
end
text.Text = tostring(tonumber(text.Text) - 1)
char:PivotTo(checkpoints[text.Text].CFrame + Vector3.new(0, 5, 0))
end)
Right Button - Local Script:
local plr = game:GetService("Players").LocalPlayer
repeat wait() until plr.Character
local char = plr.Character
local right = script.Parent
local text = script.Parent.Parent.CheckpointsLabel
local checkpoints = game.Workspace.Checkpoints
right.MouseButton1Click:Connect(function()
local stage = game.Players.LocalPlayer.leaderstats.Stage
if tonumber(text.Text) == stage.Value then
text.Text = -1
end
text.Text = tostring(tonumber(text.Text) + 1)
char:PivotTo(checkpoints[text.Text].CFrame + Vector3.new(0, 5, 0))
end)
The issue you are having is because you are setting your local char object to the value of the character at the beginning of when that script starts running. On death that character is destroyed and a new one is created. You might need to add an CharacterAdded function in that script to reset the value of your char variable when the new character is created.
You should be able to add it after your mouseclick functions. Something else you might be able to try(haven’t tried it myself) is in your mouseclick functions if the char value is nil you could do the code you have above to repeat until and set the char inside there, but you’d have to try that method.
I have tried what you said and still nothing. -edit: Nevermind, it works I just didn´t read your comment correctly … But thanks for your help, I´m really grateful .
Sometimes, like after death, there is a period when you have a player but it takes time for it to recreate the character object. So the repeat until is used to wait in the code until the character is recreated and you can access it again. You could see what I mean by opening up your character model in the workspace while running your game and resetting your character. You will see that it gets recreated but it takes time.