I'm doing a coding thing, and I need to get the character from the player, but if I use local scripts it wont show up for other players.
My code is this:
function Clicked(plr) plr.Character:FindFirstChild("Accesories"):FindFirstChild("Left Eye").Size = Vector3.new(1,1,1) end script.Parent.MouseButton1Down:Connect(Clicked)
(This is a gui btw)
When I click it, the output says Players.S_Green.PlayerGui.ScreenGui.TextButton.Script:2: attempt to index number with 'Character''
I need help...
.MouseButton1Down has 2 parameters which is x and y coordinate of the mouse.
So technically your 'plr' is the x coordinate. You need to use remote event for this
Local Script:
local plr = game.Players.LocalPlayer local event = -- your remote event here function Clicked() event:FireServer() end script.Parent.MouseButton1Down:Connect(Clicked)
Server Script:
local event = -- your remote event here event.OnServerEvent:Connect(function(plr) local char = plr.Character char:FindFirstChild("Accesories"):FindFirstChild("Left Eye").Size = Vector3.new(1,1,1) end)
Your real problem is that you need to find a way for the changes to replicate to other players. When working with GUI, your code should always go on the client, in a LocalScript. Think about it, every player has their own unique set of GUIs that are rendered only to them, it wouldn't make sense for the server to handle this for every player.
If you keep it in a LocalScript, you can make sure the changes replicate to other players by using RemoteEvents. By calling FireServer() when your button is clicked, the server will be able to access the player who fired the event so they can change the size accordingly, using the .OnServerEvent event listener.
for one, MouseButton1Down passes the coordinates that the mouse clicked at, not the player who clicked
and two, putting gui things on the server is bad practice anyway—if you need something to happen on the server when a gui is clicked, detect the input on the client and use a RemoteEvent
-- server local remote = path.to.RemoteEvent remote.OnServerEvent:Connect(function(player) player.Character.Accessories["Left Eye"].Size = Vector3.new(1, 1, 1) -- you don't need to use FindFirstChild on something that you know already exists end) -- client local remote = path.to.RemoteEvent script.Parent.MouseButton1Down:Connect(function() remote:FireServer() end)
if you don't understand how remotes work, there's a tutorial for them on the wiki