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

how to define a localplayer in the workspace?

Asked by
hokyboy 270 Moderation Voter
5 years ago

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

2 answers

Log in to vote
0
Answered by
green271 635 Moderation Voter
5 years ago

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)

0
Connect not connect User#19524 175 — 5y
0
^ forgot to capitalize the C but yes green271 635 — 5y
0
if i wanted to change the walkspeed of a person with a button that will give the local player walkspeed how to do it hokyboy 270 — 5y
0
Insert a script into the button and use the MouseButton1Down event. Perthrosama 24 — 5y
Ad
Log in to vote
0
Answered by
lunatic5 409 Moderation Voter
5 years ago

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:

1) A Player's Backpack, such as a child of a Tool

2) A Player's Character model

3) A Player's PlayerGui

4) A Player's PlayerScripts

5) 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!

Answer this question