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

"Attempt to index nil with PlayerGui", what's wrong?

I have a hit box in my game, and what it does is when a player touches it, it clones a local script that'll play a transition and then teleport the player in to a battle.

But to make sure it doesn't clone the local script multiple times, I made a blacklist. And basically the script is supposed to check if the player is in the blacklist, if they are then it returns. If they aren't then it adds them in and clones the local script into a screengui in the players backpack.

The blacklist isn't working and I keep getting the same error: "Attempt to index nil with PlayerGui". Here's my code:


Code

local blacklist = {};

script.Parent.Touched:Connect(function(hit)

local humanoid = hit.Parent:FindFirstChild("Humanoid")
if (humanoid ~= nil) then



	local Player = game.Players:GetPlayerFromCharacter(humanoid.Parent)
	humanoid.Parent.Humanoid.WalkSpeed = -100
	humanoid.Parent.Humanoid.JumpPower = -100

	wait(1.20)


	humanoid.Torso.CFrame = CFrame.new(-1475.4, 266.463, -612)


end

end)

local players = game:GetService("Players");

function foundInList(player) for _,target in ipairs(blacklist) do if target == player then return true; end end return false; end

script.Parent.Touched:connect(function(hit)

local player = players:GetPlayerFromCharacter(hit.Parent);

local ShowGUI = game.ServerStorage:FindFirstChild("ShowGUI4")

if ShowGUI ~= nil then

	game.ReplicatedStorage.Events.BlackScreen4:FireAllClients()
	ShowGUI.Parent = player.PlayerGui

end

end);

1 comment

0

Sorry about the code box not being right. I don't know how I can fix it.

1 answer

Try with this

script.Parent.Touched:Connect(function(hit)
       local player = game.Players:GetPlayerFromCharacter(hit.Parent)

local ShowGUI = game.ServerStorage:FindFirstChild("ShowGUI4")

if ShowGUI ~= nil then

    game.ReplicatedStorage.Events.BlackScreen4:FireAllClients()
    ShowGUI.Parent = player.PlayerGui

end
end)

2 comments

0

That didn't change anything. And I don't see what you changed about my code except removing all the ;

0

I think you're just talking about the code box. But I'm not sure.

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