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

Why won't this Gui script work?

Asked by 10 years ago

This is supposed to destroy the gui

function Play()
game.StarterGui.ScreenGui.Parent.Parent.Parent:Remove() 
end

script.Parent.MouseButton1Click:connect(Play)

Output:Players.Player1.PlayerGui.ScreenGui.Frame.TextButton.LocalS:2: attempt to index field 'Parent' (a nil value) What does that output mean?

1 answer

Log in to vote
0
Answered by 10 years ago

On line two, you are attempting to ':Remove()' a nil value, heres what I mean;

Game
    StarterGui
        ScreenGui

Your script is trying to do this;

--A nil value/parent that does not exist
Game --The parent of Game is nil
    StarterGui --The parent of StarterGui is Game
        ScreenGui --The parent of ScreenGui is StarterGui

You are attempting to remove a nil-like parent that does not exist, and if you removed the ScreenGui from StarterGui, then onReset, others won't beable to get the GUI, I'd do this instead;

local function Play()
script.Parent.Parent:Destroy()
end

script.Parent.MouseButton1Down:connect(Play)

And heres how you'd do this in game;

Game
    StarterGui
        ScreenGui
            TextButton/ImageButton
                LocalScript

Hope this helped! :)

0
I actully had game startergui screengui TextButton Textlabel iluvmaths1123 198 — 10y
0
Oh, then, you were probly attempting to use '.MouseButton1Down' on TextLabel, that which is not possible, I'd do instead 'script.Parent.Parent.MouseButton1Down:connect(Play)' would connect the event and function to TextButton. TheeDeathCaster 2368 — 10y
Ad

Answer this question