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

:LoadCharacter() not functioning properly?

Asked by 7 years ago
game.Player.PlayerAdded:connect(function(player)
    player:LoadCharacter()
    print("1")

    player.CharacterAdded:connect(function(character)
        print("2")
        character.Parent = workspace:WaitForChild("PlayerHolder")
    end)
end)

It prints 1 in the output, but doesn't print 2. Why is this? I have CharacterAutoLoads turned to false

Basically what I'm trying to do is keep all the players inside a folder in workspace, PlayerHolder so I get to their characters easier.

2 answers

Log in to vote
3
Answered by 7 years ago
Edited 7 years ago

The reason why the function isn't working is because you don't set up the event when you first Load the character.

You have to set up the event and function before calling the LoadCharacter function in order for it to fire.

game.Player.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        print("2")
        character.Parent = workspace:WaitForChild("PlayerHolder")
    end)

    print("1")
    player:LoadCharacter()
end)
0
This. shayner32 478 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

It's because, you can't load the character before it has been added

game.Player.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        player:LoadCharacter()
    print("2")
        character.Parent = workspace:WaitForChild("PlayerHolder")
    end)
end)

So basically, loadcharacter just refreshs/ respawns the character. It doesn't "load" it, in terms of what you were thinking of.

0
I don't think so OldPalHappy 1477 — 7y
2
This wouldn't work. It'd just make an infinite loop of re-loading the character when it's loaded once. shayner32 478 — 7y

Answer this question