Can anyone tell me why this SurfaceGui tool giver gives me this error?
Workspace.ClickPart.SurfaceGui.Button.:2: attempt to index local 'playerWhoClicked' (a nil value)
Here is the code:
function givetool(playerWhoClicked) if playerWhoClicked:GetRoleInGroup(1) >= 6 and playerWhoClicked.TeamColor == BrickColor.new("Brown") then local toolclone = game.ServerStorage.TestTool:Clone() testtool.Parent = playerWhoClicked.Backpack else print("Unauthorized request!") end end script.Parent.MouseButton1Click:connect(givetool)
MouseButton1Click doesn't detect who clicked. You'll need to use game.Players.LocalPlayer
in a local script, and set the adornee of the SurfaceGui from another script.
Just in case you didn't know this I'll say it anyway: SurfaceGui's must be in the PlayerGui and then the Adornee property needs to be set to the part that the surfacegui is on.