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

My destroy function code is not working When I run the code it doesnt work.Can you check my code?

So when you first start the game there would be a welcome screen GUI. I want to make a close button that destroys the GUI so it doesn't appear again after respawning because that is the current problem I have in my game. I made a local script in the text button and had this code that I made in there. It doesn't work and it just stops the game for 30 seconds.

function destroyGUI()
	
	game.StarterGui.ScreenGui.Frame.TextButton = destroyGUI()
end

script.Parent.MouseButton1Click:Connect(destroyGUI)

1 comment

0

Try this:

2 answers

I don't think destroyGUI() is a thing.. change your line 3 into this

game.StarterGui.ScreenGui.Frame.TextButton:Destroy()

3 comments

0

Btw if you want to Delete the playerGui that script probably won't work (Or it'll work because i'm dumb) Because the gui is cloned to game.Player.Player and the Gui folder

0

And you forgot to edit your code :/

0

edit....what? i'm dumb

Try this:

script.Parent.MouseButton1Click:Connect(function(plr) -- plr is the player that clicked the button
	local Gui = plr.PlayerGui:FindFirstChild("ScreenGui")
	if Gui ~= nil then -- Checks if the player owns the gui
		Gui:Destroy()
	end
end)

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