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

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

Asked by 6 years ago

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!}

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. Azarth 3141 — 6y
0
what could I subsitute LocalPlayer with in a script? Goldenkings11 -11 — 6y
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. Azarth 3141 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You're most likely trying to index LocalPlayerfrom a Server Script. LocalPlayercan only be indexed in a LocalScript.

0
I have a click detector in that script and when I tried LocalScript it didn't work either. Goldenkings11 -11 — 6y
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 PyccknnXakep 1225 — 6y
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. hiimgoodpack 2009 — 6y
Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

Answer this question