Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Character Nil Loading Problem?

Asked by 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
Ad
Log in to vote
1
Answered by 5 years ago

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)
0
what if player first loads with character HappyTimIsHim 652 — 5y

Answer this question