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

Attempt to index nil with PlayerGui, how do i fix it?

Asked by 3 years ago

Hello, this script was made for arrest system, however when I am clicking on it nothing happens and console says "Attempt to index nil with PlayerGui" This is the script:

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
                    local Gui = game.ServerStorage.NYPDBookPlayer:Clone()
                    Gui.Parent = Player.PlayerGui
                    Gui.Suspect.Value = game.Players:FindFirstChild(Player.Backpack.Grab.Suspect.Value)
end)

1 answer

Log in to vote
1
Answered by 3 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your answer.

You're putting "Player" instead of "plr", where you defined it. Your code would instead be

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")
    local Suspect = game.Players:FindFirstChild(Player.Backpack.Grab.Suspect.Value)
    if Suspect then
        local Gui = game.ServerStorage.NYPDBookPlayer:Clone()
        Gui.Parent = Player
        Gui.Suspect.Value = Suspect
    end
end)
0
Thanks Pancio10_alt 4 — 3y
0
Now it says grab isnt valid member of backpack while i have it in my inventory Pancio10_alt 4 — 3y
0
Again, use :WaitForChild() on Backpack. (Backpack = Player:WaitForChild("Backpack")) TheGalaxyRBLX 222 — 3y
0
Where do i put it? I am new at scripting Pancio10_alt 4 — 3y
Ad

Answer this question