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

Can You Use "game.Players.LocalPlayer" in a normal Script?

I was having some issues with scripts earlier, the problem seemed to be this line of code:

game.Players.LocalPlayer

I was wondering if "game.Players.LocalPlayer" was functional in a normal script.

(The script ended up working when I copied it into a LocalScript)

2 comments

0

'LocalPlayer' is no longer supported on a Server-Sided script, only to a Client-Sided script is it supported now.

0

Thanks @TheAlphaStigma, I had some issues with it in Studio Test Mode. "LocalPlayer" WAS working in Studio Test Mode, probably because it's classified as "Play Solo."

2 answers

✓ Accepted answer

Normal "Script" objects are run by the server; that means it doesn't have a notion of one particular player being "special", so it can't pick the LocalPlayer.


In Test Solo, Scripts will identify the LocalPlayer -- it's unambiguous, since there can only be one. I think this is done so that there is not a need to simulate two separate copies of the world when testing.

Running with a Test Server will actually separate the behavior of LocalScripts from normal Scripts.


Summary No, you can't: LocalPlayer should only be used in LocalScripts -- otherwise it will be nil (except when testing, so be careful).

1 comment

0

Thanks Taslem, that clears it up a lot.

game.Player.LocalPlayer Can only be used in A Local Script Because Regular Script can not declare a LocalPlayer Only A Local Script Would Define The "Local Player"

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