Custom Spawn does not work

I am trying to move the character to a brick’s location once he joins the game, but apparently, this does not work? It is a Local Script in StarterCharacterScripts.

game.Players.PlayerAdded:Connect(function(player)
	local char = player.Character
	local CustomSpawn = game.Workspace.CheckpointsRBX.CustomSpawn
	
	char.HumanoidRootPart.CFrame = CustomSpawn.CFrame
	
end)
2 Likes

PlayerAdded won’t run in a local script (it also only runs the first time a player joins), your code should be a local script in StarterPlayerScripts
It should look like this.

local Players = game:GetService("Players")
local player = Players.LocalPlayer

player.CharacterAdded:Connect(function(char)
    local CustomSpawn = game.Workspace.CheckpointsRBX.CustomSpawn
	
    char.HumanoidRootPart.CFrame = CustomSpawn.CFrame
end)

CharacterAdded runs Everytime the players character gets added to the workspace, which always happens upon respawn.

Also you can just set the players respawn position instead of this.

3 Likes

just replace your code with this

local CHARACTER = script.Parent -- this will only work if the script is inside StarterCharacterScripts
local HRP = CHARACTER:WaitForChild('HumanoidRootPart')

HRP.CFrame = CUSTOM_SPAWN.CFrame