script.Parent.OnServerEvent:Connect(function(player) local spoon = game.ReplicatedStorage.EraserMaking.Spoon:Clone() if spoon.Parent ~= player then spoon.Parent = player.Backpack end end)
There is the script, how does it know which player clicked it? It works, I just dont understand how the 'player' function variable is returned to it, and/or how it knows who the player is. It is also obviously connected to a remote event.
Edit: Here is the other half of the remote event if you guys need to see it.
local givercd = game.Workspace.House.Countertop["Spoon Drawer"].ClickDetector givercd.MouseClick:Connect(function() givercd.Parent.RemoteEvent:FireServer() end)
In your function, player
is a parameter (also called an argument, though there's a difference). When the OnServerEvent is fired, Roblox will send in the arguments (as described in the API) regardless of what name you give those parameters - only order matters. You can change the name of the player
parameter to whatever you want (assuming you change the rest of the function to use that new name), so long as you keep it as the first parameter.
[Edit]
ihatecars100 is correct. A Roblox server knows which client it's communicating with (ex they all have a different IP); it has assigned a Player object for each client. So, it only has to look up which Player object is associated with the client it just received a message from and then call your function with that Player object.