Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Attempt to call a nil value?

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)

1 answer

✓ Accepted answer

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.

1 comment

0

Thanks.

This discussion is preserved as it was. New answers, comments, and votes are closed.