Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Character Nil Loading Problem?

I have attempted to use types of wait codes? like WaitForChild, Repeat Wait() Until, others but still get a nil error, by having such a long wait the player spawns in the air.

game.Players.PlayerAdded:Connect(function(Player)
	wait(1) -- this is the only wait that work
	game.Players:FindFirstChild(Player.Name).Character.LowerTorso.CFrame = CFrame.new(game.Workspace.Spawn.Position) + Vector3.new(0, 3, 0)
	print(Player.Name.." Test")
end)

2 answers

✓ Accepted answer

What ihatecars100 said is one of way of doing it, another would be as follows:

game.Players.PlayerAdded:Connect(function(Player) -- PlayerAdded Event!
	
	Player.CharacterAdded:Connect(function(Character) -- Make an anonymous characteradded function!
		Character.LowerTorso.CFrame = CFrame.new(game.Workspace.Spawn.Position) + Vector3.new(0, 3, 0)
		
		print(Player.Name, "Character has loaded!") -- even though character model and player object share the same name
	end)
	
	print(Player.Name, "has loaded!")
end)

Ah yes, this is a problem plenty of people have trouble with when starting.

This can be fixed by using the ‘player.CharacterAdded’ Event with wait().

game.Players.PlayerAdded:Connect(function(Player)
    local char = Player.Character or Player.CharacterAdded:wait()
    char.LowerTorso.CFrame = CFrame.new(game.Workspace.Spawn.Position) + Vector3.new(0, 3, 0)
    print(Player.Name.." Test")
end)

1 comment

0

what if player first loads with character

This discussion is preserved as it was. New answers, comments, and votes are closed.