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

How Can i locate a player in the workspace?

Asked by 3 years ago
Edited 3 years ago

i am trying to find the player in the workspace but it only works in local scripts. can you help me try to locate it regular scripts.

Failing code in regular script

local player = game.Players.LocalPlayer.Name --Find Player name
local nameofplayer = game.Workspace:FindFirstChild(player) --Get the player in workspace
script.Parent.MouseButton1Click:Connect(function()
    nameofplayer.Head.BrickColor = BrickColor3.Blue()
0
methods may differ for finding the local player in a server script. Can you please provide some code to work with, or an explanation bdam3000 125 — 3y
0
Done TeaWithMee 76 — 3y
0
Player.Character is the legitimate method... The LocalPlayer is only attributed to Client Instances, so of course the Server is incapable of reference an Object of it's kind. Ziffixture 6913 — 3y
0
Whenever i use that in the script it responds with "attempt to index nil with 'Character'" TeaWithMee 76 — 3y

2 answers

Log in to vote
0
Answered by
bdam3000 125
3 years ago
Edited 3 years ago

You should probably handle GUIs with Localscripts. You can however change the color of the head on the server using Remote Events

You can find more about remote Events and functions here: https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

Insert a remote event in ReplicatedStorage and insert a regular script into ServerScriptService

heres the Localscript: (put it in the button)

local player = game.Players.LocalPlayer
local character = player.Character -- finds the player in the workspace
local event = game.ReplicatedStorage.   -- type the name of the remote event here

script.Parent.MouseButton1Click:Connect(function()
    event:FireServer()

put this in the regular script in ServerScriptService:

local event = game.ReplicatedStorage. -- type the name of the remote event here

event.OnServerEvent:Connect(function(player)
player.Character.Head.BrickColor = -- color here

Sorry if this is incorrect. I'm kinda new to scripting too

0
there are no errors posted but nothing happens TeaWithMee 76 — 3y
0
is the localscript inside a textbutton in StarterGui? bdam3000 125 — 3y
0
Im using a regular script and its inside of a text button TeaWithMee 76 — 3y
0
you need to use a localscript rather than a regular script. Just insert a localscript into the button and paste the 1st code block above (make sure to edit where the green text is to your liking) bdam3000 125 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

Your going to have to use RemoteEvents in order to do this. This is due to ROBLOX Filtering Enabled restrictions.

Answer this question