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

Attempt to index nil with 'destroy' | Trying to destroy a GUI | (?)

Asked by 1 year ago

I followed a youtube tutorial, and I know the very basics of scripting but I'm gradually learning. When attempting to run the last part of the script, I get the error "ServerScriptService.OverheadHandler:17:attempt to index nil with 'destroy'" Can anyone help?

local serverStorage = game:GetService("ServerStorage")

game.Players.PlayerAdded:Connect(function(plr)
    plr.CharacterAdded:Connect(function(char)
        local level = plr:WaitForChild("leaderstats").Rank.Level
        local levelVal = level.Value
        local rankTag = serverStorage:FindFirstChild(levelVal):Clone()
        rankTag.Parent = char.Head
        plr.leaderstats.Rank.Level.Changed:Connect(function()
            local level = plr:WaitForChild("leaderstats").Rank.Level
            local levelVal = level.Value
            local rankTag = serverStorage:FindFirstChild(levelVal):Clone()
            rankTag.Parent = char.Head
            local lastRank = levelVal - 1

            if lastRank > 0 then
                char.Head:FindFirstChild(lastRank):Destroy()
            end
        end)
    end)
end)

1 answer

Log in to vote
0
Answered by
kiref81 -24
1 year ago

You cant destroy GUI u can only make it unvisible

GUI = char.Head:FindFirstChild(lastRank)
GUI.Visible = False
0
I did that, it doesn't do it either, the issue seems to be that the GUI is parented to the player, and not their head. esmith68789 9 — 1y
0
Wait, nevermind, I figured out how to make your code work. Thanks! esmith68789 9 — 1y
Ad

Answer this question