I’m trying to change the player’s spawnpoint by making them get teleported to the spawnpoint every time that their character is created. However they are still just spawning in the middle of nowhere. Here is my script.
local function onCharacterAdded(character)
for i, v in pairs(workspace:GetChildren()) do
if v.Name == “SpawnLocation” then
local player = game.Players:GetPlayerFromCharacter(character)
if v.CheckpointNumber.Value == player.leaderstats.Stage.Value then
character.HumanoidRootPart.Position = v.Position
end
end
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
It is because you are using “ and ”. It will prevent your script from running. Try using " " " " " " < copy this
local function onCharacterAdded(character)
for i, v in pairs(workspace:GetChildren()) do
if v.Name == "SpawnLocation" then -- Error was here. Fixed it.
local player = game.Players:GetPlayerFromCharacter(character)
if v.CheckpointNumber.Value == player.leaderstats.Stage.Value then
character.HumanoidRootPart.Position = v.Position
end
end
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(onCharacterAdded)
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
You are using apostrophe but in scripts you should use quotes.
Thanks but I don’t think that the problem in the script was with the quotations. The script was able to find the correct spawn location (I put print(v.Position) and it was able to do it successfully) but the problem is that it doesn’t move the player on top of the spawnpoint. So I am pretty sure the problem is with this part:
Seems like there’s an odd issue with Roblox teleportation as the character loads. I noticed that adding some sort of wait/delay before teleporting the character seems to fix the issue. Try adding something like wait() in the line right before you move the character?
I would also recommend using Character:SetPrimaryPartCFrame() instead of Character.HumanoidRootPart.Position = ... as that prevents any weird issues with part positioning going out of sync between the player’s view and the server’s view.