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

Help with Gui script?

Asked by 9 years ago

I wnat to do a tool which gives me stuff when I press a key, already did it and it works, the bug isn't when it gives but when I unequip the tool and equip it again the gui duplicates and so on.If I press when I't sduplicate I have that gui stuck in my screen forever.I've made a function that makes the gui disapear when I deselect the hopperbin and it worked but if I keep selecting and deselecting the hopper bin it duplicates.Here's the script:

wait(3)
Player = script.Parent.Parent.Parent
n = script.Parent
mouse = Player:GetMouse()
c = Player.Character
debounce =  false

function Equiped()
    h = Instance.new("ScreenGui", Player.PlayerGui)
    h.Name = "ElementGui"
    a = Instance.new("TextLabel", h)
    a.BackgroundColor3 = Color3.new(170/255, 255/255, 0/255)
    a.Visible = true
    a.Position = UDim2.new(0.3, -100, 0.3, 0)
    a.Size = UDim2.new(0.3, 200, 0.3, 50)
    a.BackgroundTransparency = 0.5
    a.Text = "F-Fire ; L-Lightning ; E-Earth ; R-Wind ; W-Water!"
    mouse.KeyDown:connect(function(key)
        local Key = key:lower()
        if key == "r" and debounce == false then
            debounce = true
            local emi = game.Lighting:WaitForChild("Wind")
            emi:Clone().Parent = Player:WaitForChild("Backpack")
            local emi2 = game.Lighting:WaitForChild("Wind Jutsu")
            emi2:Clone().Parent = Player:WaitForChild("Backpack")
            h:remove()
            n:remove()
        end
        if key == "w" and debounce == false then
            debounce = true
            local emi = game.Lighting:WaitForChild("Water")
            emi:Clone().Parent = Player:WaitForChild("Backpack")
            local emi2 = game.Lighting:WaitForChild("Water Jutsu")
            emi2:Clone().Parent = Player:WaitForChild("Backpack")
            h:remove()
            n:remove()
        end
        if key == "f" and debounce == false then
            debounce = true
            local emi = game.Lighting:WaitForChild("Fire")
            emi:Clone().Parent = Player:WaitForChild("Backpack")
            local emi2 = game.Lighting:WaitForChild("Fire Jutsu")
            emi2:Clone().Parent = Player:WaitForChild("Backpack")
            h:remove()
            n:remove()
        end
        if key == "l" and debounce == false then
            debounce = true
            local emi = game.Lighting:WaitForChild("Lightning")
            emi:Clone().Parent = Player:WaitForChild("Backpack")
            local emi2 = game.Lighting:WaitForChild("Lighting Jutsu")
            emi2:Clone().Parent = Player:WaitForChild("Backpack")
            h:remove()
            n:remove()
        end
        if key == "e" and debounce == false then
            debounce = true
            local emi = game.Lighting:WaitForChild("Pillar")
            emi:Clone().Parent = Player:WaitForChild("Backpack")
            local emi2 = game.Lighting:WaitForChild("Earth Jutsu")
            emi2:Clone().Parent = Player:WaitForChild("Backpack")
            h:remove()
            n:remove()
        end
    end) 

end

function Unequi()
        for i, v in pairs(Player.PlayerGui:GetChildren()) do
            if v:IsA("ScreenGui") and v.Name == "ElementGui" then
                v:remove()
            end
        end
end

function onDeselect()
    n.Deselected:connect(function() Unequi() end)
end

function onSelected()
    n.Selected:connect(function() Equiped() end)
end

n.Selected:connect(onSelected)
n.Deselected:connect(onDeselect)


1 answer

Log in to vote
0
Answered by 9 years ago

Try adding an if check to "Equiped":

function Equiped()
       if Player.PlayerGui:WaitForChild("ElementGui") == nil then
           h = Instance.new("ScreenGui", Player.PlayerGui)
           h.Name = "ElementGui"
           a = Instance.new("TextLabel", h)
           a.BackgroundColor3 = Color3.new(170/255, 255/255, 0/255)
           a.Visible = true
           a.Position = UDim2.new(0.3, -100, 0.3, 0)
           a.Size = UDim2.new(0.3, 200, 0.3, 50)
           a.BackgroundTransparency = 0.5
           a.Text = "F-Fire ; L-Lightning ; E-Earth ; R-Wind ; W-Water!"
           mouse.KeyDown:connect(function(key)
               local Key = key:lower()
               if key == "r" and debounce == false then
                   debounce = true
                   local emi = game.Lighting:WaitForChild("Wind")
                   emi:Clone().Parent = Player:WaitForChild("Backpack")
                   local emi2 = game.Lighting:WaitForChild("Wind Jutsu")
                   emi2:Clone().Parent = Player:WaitForChild("Backpack")
                   h:remove()
                   n:remove()
               end
               if key == "w" and debounce == false then
                   debounce = true
                   local emi = game.Lighting:WaitForChild("Water")
                   emi:Clone().Parent = Player:WaitForChild("Backpack")
                   local emi2 = game.Lighting:WaitForChild("Water Jutsu")
                   emi2:Clone().Parent = Player:WaitForChild("Backpack")
                   h:remove()
                   n:remove()
              end
              if key == "f" and debounce == false then
                 debounce = true
                 local emi = game.Lighting:WaitForChild("Fire")
                 emi:Clone().Parent = Player:WaitForChild("Backpack")
                 local emi2 = game.Lighting:WaitForChild("Fire Jutsu")
                 emi2:Clone().Parent = Player:WaitForChild("Backpack")
                 h:remove()
                 n:remove()
              end
                if key == "l" and debounce == false then
                    debounce = true
                    local emi = game.Lighting:WaitForChild("Lightning")
                    emi:Clone().Parent = Player:WaitForChild("Backpack")
                    local emi2 = game.Lighting:WaitForChild("Lighting Jutsu")
                    emi2:Clone().Parent = Player:WaitForChild("Backpack")
                    h:remove()
                    n:remove()
                end
                if key == "e" and debounce == false then
                    debounce = true
                    local emi = game.Lighting:WaitForChild("Pillar")
                    emi:Clone().Parent = Player:WaitForChild("Backpack")
                    local emi2 = game.Lighting:WaitForChild("Earth Jutsu")
                    emi2:Clone().Parent = Player:WaitForChild("Backpack")
                    h:remove()
                    n:remove()
                end
            end) 

       end
end


0
It doesn't even show me the gui anymore... brokenrares 48 — 9y
Ad

Answer this question