You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want to teleport a player’s character to a location right after they spawn
What is the issue?
It won’t work for whatever reason. I printed the character’s parent after it spawns and it says nil?
What solutions have you tried so far?
I had a problem with “attempt to index nil with SetPrimaryPartCFrame” so I used player.CharacterAdded, this seems to have a problem as well.
local players = Players:GetPlayers() --Get the players
for index, player in ipairs(players) do --Atempt to teleport the two players' characters
local character = player.Character
if not character then --If character hasn't loaded
character = player.CharacterAdded:Wait() --Wait until it has
print(character,character.Parent) -- this prints "(Character Name, nil)
end
if index == 1 then --Just teleporting them
character:SetPrimaryPartCFrame(CFrame.lookAt(Vector3.new(0,5,40),Vector3.new(0,0,0)))
elseif index == 2 then
character:SetPrimaryPartCFrame(CFrame.lookAt(Vifctor3.new(0,5,-40),Vector3.new(0,0,0)))
end
end
If the character hasn’t loaded before the check, then the parent is nil. How do I fix this? It also doesn’t give an error when I try to teleport the orphan character, it just does nothing and gives no error. Any Ideas? I’ve already tried
local players = Players:GetPlayers()
for index, player in ipairs(players) do
local character = player.Character or player.CharacterAdded:Wait()
if index == 1 then --Just teleporting them
character:SetPrimaryPartCFrame(CFrame.lookAt(Vector3.new(0,5,40),Vector3.new(0,0,0)))
elseif index == 2 then
character:SetPrimaryPartCFrame(CFrame.lookAt(Vifctor3.new(0,5,-40),Vector3.new(0,0,0)))
end
end
I’m not sure why the parent is not workspace, if you see the video link I posted above this, it prints out the character and its parent. However, the second character’s parent is nil which I’m assuming is why it doesn’t teleport.
The first teleport is fine, I’m worried about the second teleport in the place. You can see that the first player got up to the platform fine, that’s supposed to happen. However mine didn’t. You can see that I printed the character and the character’s parent and the player that didn’t teleport was an orphan with a parent of nil for some reason.