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

How to use CharacterAdded from a local script?

game.Players.LocalPlayer.CharacterAdded just isn't a thing so I don't know what to do. Please help me get the character instance of teh local player from one localscript whenever the character respawns or spawns in the first time.

Thanks :3

pcall(function()

     wait()

     game.Players.LocalPlayer.CharacterAdded:Connect(function()

          print"t"

     end)

end)

6 comments

1

game.Players.LocalPlayer.CharacterAdded does indeed work in local scripts.

0

It doesnt work for me what can i be doing wrong?

0

Can you post your code?

0

Yes

1

If it doesn't work for you, then you might want to say CharacterAdded in a normal script and fire a remove event to the local script

0

I stated that i want to do this all in one local script

1 answer

✓ Accepted answer

##Problem:

The reason it doesn't work is because of the :Wait(). The :Wait() yields the script until an event is true, and in your script, the player would have already been in the game which would cause it not to work!

Solution: Simply remove the wait() function, and your problem is resolved.

Quick fact: :Waits() are usually 0.03 to 0.07 seconds long!

Also you don't really need a pcall in this case, it's up to you if you want to use it, but it isn't needed here!

Thanks, JesseSong!

4 comments

1

Remember to place it in starterplayer

0

Thank you ill try this, but would it work in screengui

0

no, screengui is only for gui frames. i think you meant startergui, if thats what you meant then no, since you can't get the character in startergui

0

if you have more question, please comment

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