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

How would i disable this gui after it is clicked?

I was wondering how to make a gui dissapear after it's clicked and when the character respawns it would reapear. Here is my script just to see if you coulda find something wrong. I tried game.StarterGui.Swordsmangiver.Disabled but it did not not work. if you could help me that would be greatly appreciated.

-- creating a screen gui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

--make a text button
local textButton = Instance.new ("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0,50,0,150)
textButton.Size = UDim2.new(0,140,0,60)
textButton.TextColor3 = BrickColor.White().Color
textButton.Style = 3
textButton.Text = "Swordsman"

--Bind function to button click
textButton.MouseButton1Down:connect(function()
p = game.Players.LocalPlayer
sword = game.ReplicatedStorage.ChristmasTreeSword:clone()--Weapon name
shield = game.ReplicatedStorage.Shield:clone()
if p.Backpack:FindFirstChild(sword.Name)~= nil then return end
if p.Backpack:FindFirstChild(shield.Name)~= nil then return end
p.Backpack:ClearAllChildren()
sword.Parent = p.Backpack
shield.Parent = p.Backpack
p.Character.Humanoid.WalkSpeed = 18
end)

Things to consider: This is a localscript inside the StarterGui. The script works and everything but i don't know how to disable after click and renable after death.

1 comment

0

Turn off the visibility, it'll reactivate automatically if it's in startergui.

1 answer

✓ Accepted answer

Assuming you want it do disable after clicking the textButton:

-- creating a screen gui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

--make a text button
local textButton = Instance.new ("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0,50,0,150)
textButton.Size = UDim2.new(0,140,0,60)
textButton.TextColor3 = BrickColor.White().Color
textButton.Style = 3
textButton.Text = "Swordsman"

--Bind function to button click
textButton.MouseButton1Down:connect(function()
p = game.Players.LocalPlayer
sword = game.ReplicatedStorage.ChristmasTreeSword:clone()--Weapon name
shield = game.ReplicatedStorage.Shield:clone()
if p.Backpack:FindFirstChild(sword.Name)~= nil then return end
if p.Backpack:FindFirstChild(shield.Name)~= nil then return end
p.Backpack:ClearAllChildren()
sword.Parent = p.Backpack
shield.Parent = p.Backpack
p.Character.Humanoid.WalkSpeed = 18

screenGui:Destroy()

end)

Let me explain this. When the player spawns, the things from StarterGui clone into his PlayerGui. When I destroy the screenGui, I only destroy it from the PlayerGui, not the StarterGui (Where it gets cloned from). This means that when the player spawns again, the Gui can be used like normal.

2 comments

0

Ok You've helped me see how this works now so ive named all my gui's now. lets say this one is screenGui1. How would i also destroy screenGui2,screenGui3,and screenGui4 all in this same script?

0

You can just simply do: screenGui1:Destroy() screenGui2:Destroy() screenGui3:Destroy() screenGui4:Destroy() ..

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