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

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

Asked by 4 years ago

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)
0
Try this: TTHKKB 12 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

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

game.StarterGui.ScreenGui.Frame.TextButton:Destroy()
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 Nguyenlegiahung 1091 — 4y
0
And you forgot to edit your code :/ Block_manvn 395 — 4y
0
edit....what? i'm dumb Nguyenlegiahung 1091 — 4y
Ad
Log in to vote
0
Answered by
TTHKKB 12
4 years ago

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)

Answer this question