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

Why is this script with game.Players.LocalPlayer working in Studio Mode and not Player Mode?

I am making a game called Crop Farm Tycoon and when you click the soil it gives you seeds. Now when you click the seed it is suppose to grow the crop. Please Note that this script works in studio mode, but not in Player Mode.

I have been reading articles saying that LocalPlayer does not always work in scripts. How do I fix this?

I use the script line,

game.Players.LocalPlayer

..but that only works in Studio Mode and when I test it in Player Mode it is like I never even done the script!

{ All I want to know is what to use instead of LocalPlayer to make this work work please give me a main thing that means localplayer, but isn't actually localplayer with an explanation please!}

3 comments

1

LocalPlayer NEVER works in normal scripts, not unless you pass it from a LocalScript using a RemoteEvent/Function. It works in Studio because the client/server relationship isn't the same as online.

0

what could I subsitute LocalPlayer with in a script?

1

You can put a LocalScript in StarterCharacterScripts and use Button1Down and mouse.Target. Send your player to a server script using a RemoteEvent and continue your code through this script. You should be implementing Filtering Enabled this way anyways.

2 answers

✓ Accepted answer

You're most likely trying to index LocalPlayer from a Server Script. LocalPlayer can only be indexed in a LocalScript.

3 comments

0

I have a click detector in that script and when I tried LocalScript it didn't work either.

0

LocalScripts don't work in the workspace. You need to use the Players service from a regular script. http://wiki.roblox.com/index.php?title=API:Class/Players

1

If LocalScripts work in the workspace, what would LocalPlayer be? Scripts can't read your mind on what you want to do. They just do what you tell them to do.

LocalScript can only access the LocalPlayer.

A solution could be to put a local script into one of the StarterServices, preferably StarterCharacterScripts.

NOTE: Make sure to use UserInputService instead of mouse for keyboard button pushing.

But if you mean to click a part that isn't a GUI button, you can use the instance ClickDetector and use .MouseClick connection for that instance into your script.

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