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

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

Asked by 9 years ago

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 2368 — 9y
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 — 9y

2 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 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 — 9y
Ad
Log in to vote
0
Answered by 7 years ago

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"

Answer this question