[SOLUTION]: I realized the problem had been that the script was working, but it was teleporting the player before the character actually loaded, even though I had waited for the variables to load. Oh well, I guess mistakes happen when you move super fast. The way I fixed it was adding a repeat wait() until plr.Character ~= nil after the character added event
I’ll try to make this short because I don’t think its an advanced problem. If you need clarification on how I have the system set up please let me know. I have this script that is supposed to work for checkpoints using a value for the player’s stage. It works when the player spawns and the stage is 0, but after I change my stage to 1 and reset it doesn’t work.
Portion of Script:
plr.CharacterAdded:Connect(function(char)
--below will move the character
if plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value > 0 then
print("hi")
char:WaitForChild("HumanoidRootPart").Position = workspace.Checkpoints:FindFirstChild(plr.leaderstats.Stage.Value).Position + Vector3.new(0,5,0)
else
char:WaitForChild("HumanoidRootPart").Position = workspace.MainSpawn.Position + Vector3.new(0,5,0)
end
```
changing the humanoidrootpart’s position glitches it out. Instead, change its CFrame.
plr.CharacterAdded:Connect(function(char)
--below will move the character
if plr:WaitForChild("leaderstats"):WaitForChild("Stage").Value > 0 then
print("hi")
char:WaitForChild("HumanoidRootPart").CFrame = workspace.Checkpoints:FindFirstChild(plr.leaderstats.Stage.Value).CFrame + Vector3.new(0,5,0)
else
char:WaitForChild("HumanoidRootPart").CFrame = workspace.MainSpawn.CFrame+ Vector3.new(0,5,0)
end
end)
Just tried, it worked for the MainSpawn but still not the actual checkpoint. I’m really not sure why this is happening but could it have to do with other character added events firing in other scripts? I dont change the character position in any but its all i can think of.
It may be happening cuz of the other scripts so you can put a wait() in the script.
And are you getting the Stage value with datastore?
(Because This script will run when the player’s character is loaded. And you have to change the value of the stage before this script runs.)
WHen teleporting the user, I reccomend you use CFrames rather than Position. Position may glitch out, and CFrames are reliable and better in this case.
This is the script I use on my own Obby stages. Though it may differ from yours it may give you an idea on what to change in your own script.
plr.CharacterAdded:connect(function(char)
local humanoid,hrp = char:WaitForChild("Humanoid"),char:WaitForChild("HumanoidRootPart")
wait()
if humanoid and hrp then
if stage.Value ~= 0 then
local part = workspace.ObbyStages:FindFirstChild(stage.Value) -- Change to your stages folder
hrp.CFrame = part.CFrame + Vector3.new(0,5,0)
end
end
end)
end)
Check formatting as i’m still new to the formatting here on the site.
Please use Instance.new() and create a IntValue inside a folder named ServerData in the script. Everytime a player hits a checkpoint, the boolvalue´s value increases by 1.
Yes they are, when the player steps on the checkpoint it changes their stage value to the name of the part as well using tonumber so the numbers should be set up correctly.
Now I’m quite confused. I tried your method and included prints. I have yet to receive an error message or an unwanted print. For example, it always prints that the humanoid and humanoid root part exist, yet it doesn’t teleport it as specified in the following line. Also, the character teleports to the main spawn when they first enter the game, but after resetting or dying they do not.
plr.CharacterAdded:Connect(function(char)
--below will move the character
local humanoid, hrp, stage = char:WaitForChild("Humanoid"), char:WaitForChild("HumanoidRootPart"), plr:WaitForChild("leaderstats"):WaitForChild("Stage")
if stage.Value > 0 then
print(plr.Name.."'s stage is "..tostring(stage.Value)..", which is over 0")
if humanoid and hrp then
print("Humanoid and humanoid root part exist")
hrp.CFrame = workspace.Checkpoints:FindFirstChild(stage.Value).CFrame + Vector3.new(0,5,0)
end
else
print(plr.Name.."'s stage is "..tostring(stage.Value)..", which is less than or equal to 0")
if humanoid and hrp then
print("Humanoid and humanoid root part exist")
hrp.CFrame = workspace.MainSpawn.CFrame + Vector3.new(0,5,0)
else
print("They don't exist")
end
end
I will say that the stage .value is stored in my datastore and since some of my updates I’ve not been able to pinpoint why I spawn on the originating spawn location for my level. However I have a teleporting system that allows teleportation from last checkpoint to lobby and vice versa so I haven’t had to dig into it much. My main script provides the stage.value after loading and then is supposed to teleport the player to the last saved checkpoint. But as stated earlier it takes me now to the lobby area (the main start spawn for the game) I’ve been working on a pet system so I’ve been digging into that all day, im sorry that my suggestion did not work.