how to get a localplayer in workspace ik for the game.players its just.LocalPlayer But it doent work in the workspace how to do it
how to define a localplayer in the workspace?
2 answers
You can only call Localplayer from a localscript. You have to use another method of finding the player with server scripts. For instance, in a RemoteEvent you can do:
game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(function(player)
Well, I'm assuming you're using a LocalScript (if you aren't using a LocalScript then you need to be using one to define a LocalPlayer) and want to define the player's Character that is located in Workspace (and not the player as in what is found in the Players tab in Studio). If that is what you are asking, then you can define a player and the player's Character like this:
local player = game.Players.LocalPlayer
local char = workspace:WaitForChild(player.Name)
Also, when using a LocalScript, you must place it in one of 5 locations. According to the ROBLOX Wiki, these 5 locations are the following:
A Player's Backpack, such as a child of a Tool
A Player's Character model
A Player's PlayerGui
A Player's PlayerScripts
The ReplicatedFirst service
I don't know if this is what you are looking for, but if it is and this works, please accept my answer. Hope this helps!
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Connect not connect
^ forgot to capitalize the C but yes
if i wanted to change the walkspeed of a person with a button that will give the local player walkspeed how to do it
Insert a script into the button and use the MouseButton1Down event.