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

Why won't this Gui script work?

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

✓ Accepted answer

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! :)

2 comments

0

I actully had game startergui screengui TextButton Textlabel

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.

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