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

How to delete something if it finds ? (Not working)

Basically, a close button that if it finds something in player's gui, delete the gui and delete the main gui. But it doesn't work, no errors

local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("WeaponShopLABEL")
local main = script.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function()
	if GUI ~= nil then
		print("nil") -- doesn't print
	GUI:Destroy()
	main:Destroy()
end
end)

1 answer

The problem is likely that you only check to see if it exists once, and refer to that result every time the the button is clicked. Instead, you need to check every time it is clicked, like this:

local main = script.Parent.Parent.Parent

script.Parent.MouseButton1Click:connect(function()
	local GUI = game.Players.LocalPlayer.PlayerGui:FindFirstChild("WeaponShopLABEL")
	if  GUI then
		print("nil")
		GUI:Destroy()
		main:Destroy()
	end
end)

3 comments

0

that won't work, your GUI variable is nil

0

I have fixed that.

0

Thanks, i will test it when im at pc!

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