Unable to teleport player to a part on spawn?

I want to teleport a player’s character as soon as they spawn, however it does not do that. I’ve tried all kinds of waits, to no avail

player.CharacterAdded:Connect(function(character)
	player.CharacterAppearanceLoaded:Wait()
	--wait()
	print("LOADED")
	character:SetPrimaryPartCFrame(PlayersIsland.Spawn.CFrame + Vector3.new(0, 2, 0))
			
	character.Humanoid.Died:Connect(function()
		Load(player)
	end)
end)


I should be spawning on that island, where the current selected object is. My character currently spawns in mid air at 0,0,0. The platform I’m standing on is purely there to prevent the player from constantly falling through the world.

I don’t want to use SpawnLocations as they result in other players spawning on your island etc.

There are some missing words in your script. You used these words but didn’t add it as an information to your problem:

  1. player
  2. PlayersIsland

It will be better if you provide those.

Yep also this spawn part.

You sure it’s set correctly?

Edit: Nvm I see the issue now while testing it.

player is the player instance, didn’t think that was 100% necessary, as it should be obvious no??

And PlayerIsland is the thing I have my mouse selected in the game. That’s the position of it

1 Like

I can only guess that player is the LocalPlayer or is coming from PlayerAdded. That’s why I asked.

I do not know how you are getting PlayerIsland. Based on my speculation, the problem lies on how you get the object.

try this

player.CharacterAdded:Connect(function(character)
	player.CharacterAppearanceLoaded:Wait()
	--wait()
	print("LOADED")
	character.HumanoidRootPart.CFrame=PlayersIsland.Spawn.CFrame*Vector3.new(0,10,0)
			
end)

When I do

print("SPAWN TO", PlayersIsland.Spawn.Position)
character:SetPrimaryPartCFrame(PlayersIsland.Spawn.CFrame + Vector3.new(0, 2, 0))
print("CHARACTER POS", character.PrimaryPart.Position)	

SPAWN TO -312, 9, 36 - Server - PlayerManager:51
CHARACTER POS -312, 11, 36 - Server - PlayerManager:53

So according to the script, my character is spawning there, but they clearly aren’t because my HumanoidRootPart is at 0,0,0

I believe this will be solution, found from the character added documentation Player | Roblox Creator Documentation.

local RunService = game:GetService("RunService")

		-- Wait a brief moment before teleporting, as Roblox will teleport the
		-- player to their designated SpawnLocation (which we will override)
		RunService.Stepped:wait()

I also tested within studio should work, even a normal wait() works.

To debug add a CFrame changed property, it’ll see where and when the character has been teleported by the roblox spawn system or any other system:

local RunService = game:GetService("RunService")

local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character.HumanoidRootPart:GetPropertyChangedSignal("CFrame"):Connect(function()
			print(player, " has teleported here:",character.HumanoidRootPart.Position)
		end)
		player.CharacterAppearanceLoaded:Wait()
		--wait()
		RunService.Stepped:wait()
		print("LOADED")
		character:SetPrimaryPartCFrame(workspace.NewSpawnPart.CFrame + Vector3.new(0, 2, 0))
	end)
end)
5 Likes