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

How would i disable this gui after it is clicked?

Asked by 9 years ago

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.

0
Turn off the visibility, it'll reactivate automatically if it's in startergui. Goulstem 8144 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

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.

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? gigabite176 20 — 9y
0
You can just simply do: screenGui1:Destroy() screenGui2:Destroy() screenGui3:Destroy() screenGui4:Destroy() .. Vlatkovski 320 — 9y
Ad

Answer this question