Ad
Log in to vote
0

How would i destroy multiple gui's after one is clicked?

Asked by 8 years ago

Hi i am very new to scripting and with the help of you guys i've created this local script with a gui

-- 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 = 2
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
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 20
end)

Now that this script is there, i don't want people to have multiple items and abuse this script as i have 3 gui's that give different items each, and if you're holding an item it, is not destroyed. I also don't want people constantly switching classes. How would i delete multiple gui's after any one of them are clicked.

Details: guis are: Swordsmangiver, Roguegiver, Marksmangiver

Thank you for reading and taking the time to consider!

1 answer

Log in to vote
0
Answered by 8 years ago

Somewhere inside the MouseButton1Click, add the line:

-- 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 = 2
textButton.Text = "Swordsman"

--Bind function to button click
textButton.MouseButton1Down:connect(function()
for i, v in pairs(game.Players.LocalPlayer.PlayerGui:GetChildren()) do -- where are the GUI's located?
    if v then
        if v.className == 'ScreenGui' then
            if v.Name == 'Swordsmangiver' then
                v:remove()
            elseif v.Name == 'Roguegiver' then
                v:remove()
            elseif v.Name == 'Marksmangiver' then
                v:remove()
        end
    end
end)
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
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 20
end)


0
thank you very much gigabite176 20 — 8y
0
pls press 'Accept Answer' killerkill29 35 — 8y
0
Oh my bad XD gigabite176 20 — 8y
Ad

Answer this question