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

How to access player by local script?

Hello, so I have just inserted a localscript in StarterCharacterScripts and... I want to access the player, what’s wrong with my script?

Also I appreciate upvotes :)

local Player = game.LocalPlayer
print(player)

2 answers

✓ Accepted answer

You forgot to add Players between game and LocalPlayer:

local Player = game.Players.LocalPlayer

1 comment

0

Oh thank you!

StarterCharacterScripts is for accessing the character only. The character is like the NPC, except the player controls the said NPC. If you want to access the player only, then change it to StarterPlayerScripts. Also printing the instance is not allowed, and it would break your script. So the proper print is this:

local player = game.Players.LocalPlayer
print(tostring(player))

Nitpicks: You didn't capitalise Player at the 2nd line. You were supposed to write game.Players.LocalPlayer not game.LocalPlayer. Also you can't print instances unless if you use the tostring() function.

4 comments

0

Thank you, hey I’ve been trying to do a certain script in Roblox studio for a while (not this one) but a different one but I don’t know how can you help me?

0

Post a separate question and I'll see it.

0

Ok

0

I asked the question dovy

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