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

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

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

✓ Accepted 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)

4 comments

0

Thanks

0

Now it says grab isnt valid member of backpack while i have it in my inventory

0

Again, use :WaitForChild() on Backpack. (Backpack = Player:WaitForChild("Backpack"))

0

Where do i put it? I am new at scripting

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