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

Attempt to call a nil value?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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.

0
Thanks. ISellCows 2 — 9y
Ad

Answer this question