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", what's wrong?

Asked by
Desmondo1 121
3 years ago

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);

0
Sorry about the code box not being right. I don't know how I can fix it. Desmondo1 121 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

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)
0
That didn't change anything. And I don't see what you changed about my code except removing all the ; Desmondo1 121 — 3y
0
I think you're just talking about the code box. But I'm not sure. Desmondo1 121 — 3y
Ad

Answer this question