Still have questions? Join our Discord server and get real time help.
0

# 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)

0
'LocalPlayer' is no longer supported on a Server-Sided script, only to a Client-Sided script is it supported now. TheeDeathCaster 2319 — 5y
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." sidekick83 80 — 5y

0
BlueTaslem 17922
5 years ago

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).

0
Thanks Taslem, that clears it up a lot. sidekick83 80 — 5y