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

How to use CharacterAdded from a local script?

Asked by 3 years ago
Edited 3 years ago

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)
1
game.Players.LocalPlayer.CharacterAdded does indeed work in local scripts. appxritixn 2235 — 3y
0
It doesnt work for me what can i be doing wrong? AlexanderYar 788 — 3y
0
Can you post your code? appxritixn 2235 — 3y
0
Yes AlexanderYar 788 — 3y
View all comments (2 more)
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 Soban06 410 — 3y
0
I stated that i want to do this all in one local script AlexanderYar 788 — 3y

1 answer

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
3 years ago

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!

1
Remember to place it in starterplayer JesseSong 3916 — 3y
0
Thank you ill try this, but would it work in screengui AlexanderYar 788 — 3y
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 JesseSong 3916 — 3y
0
if you have more question, please comment JesseSong 3916 — 3y
Ad

Answer this question