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

Why, after I press the button once, do I have to press it twice to activate it again?

Asked by 8 years ago

I've been working on a GUI which lets you select an ability and upon clicking it, activates it. After I click the button, the ability activates, and the cooldown starts, but after the cooldown has finished and the button becomes clickable again, I have to double click to activate it. I'm a Lua newbie and I've searched through the code and can't find anything related to the problem. I've used multiple scripts placed with the text button - here they are.

toggle = script.Parent

function cooldown()
    if script.Parent.Switch.Value == false and script.Parent.Cooldown.Value == false then
        wait(0.5)
        script.Parent.BackgroundColor3 = Color3.new(24,0,0)
        script.Parent.Cooldown.Value = true
        toggle.Text = "10"
        wait(0.5)
        toggle.Text = "9"
        wait(1)
        toggle.Text = "8"
        wait(1)
        toggle.Text = "7"
        wait(1)
        toggle.Text = "6"
        wait(1)
        toggle.Text = "5"
        wait(1)
        toggle.Text = "4"
        wait(1)
        toggle.Text = "3"
        wait(1)
        toggle.Text = "2"
        wait(1)
        toggle.Text = "1"
        wait(1)
        toggle.Text = "Activate Particles!"
        script.Parent.BackgroundColor3 = Color3.fromRGB(0,128,0)
        script.Parent.Cooldown.Value = false
    end
end

script.Parent.MouseButton1Up:connect(cooldown)
player = script.Parent.Parent.Parent.Parent.Parent
char = player.Character

function cloak()
if (script.Parent.Switch.Value~=true) and script.Parent.Cooldown.Value == false then
script.Parent.Switch.Value = true
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v.Handle.Transparency = 1
end end 
char.Head.Transparency = 1
char.Torso.Transparency = 1
char:findFirstChild("Left Arm").Transparency = 1
char:findFirstChild("Right Arm").Transparency = 1
char:findFirstChild("Left Leg").Transparency = 1
char:findFirstChild("Right Leg").Transparency = 1
else
for i,v in pairs(char:GetChildren()) do
if v:IsA("Hat") then
v.Handle.Transparency = 0
end end  
script.Parent.Switch.Value = false
char.Head.Transparency = 0
char.Torso.Transparency = 0
char:findFirstChild("Left Arm").Transparency = 0
char:findFirstChild("Right Arm").Transparency = 0
char:findFirstChild("Left Leg").Transparency = 0
char:findFirstChild("Right Leg").Transparency = 0
end
    end 
script.Parent.MouseButton1Up:connect(cloak)
player = script.Parent.Parent.Parent.Parent.Parent
char = player.Character

function cloak()
    if script.Parent.Switch.Value == false and script.Parent.Cooldown.Value == false then
        char.Humanoid.WalkSpeed = 24
        x = Instance.new("ParticleEmitter",char.Torso)
        s = Instance.new("Sparkles",char.Torso)
        wait(7)
        char.Humanoid.WalkSpeed = 16
        char.Head.Transparency = 0
        char.Torso.Transparency = 0
        char:findFirstChild("Left Arm").Transparency = 0
        char:findFirstChild("Right Arm").Transparency = 0
        char:findFirstChild("Left Leg").Transparency = 0
        char:findFirstChild("Right Leg").Transparency = 0
        for i,v in pairs(char:GetChildren()) do
        if v:IsA("Hat") then
        v.Handle.Transparency = 0
        end end 
        x:destroy()
        s:destroy()
    else
        if script.Parent.Switch.Value == true then
            char.Humanoid.WalkSpeed = 16
            x:destroy()
            s:destroy()
        end
    end
end

script.Parent.MouseButton1Up:connect(cloak)
player = script.Parent.Parent.Parent.Parent.Parent
char = player.Character

function playleSound()
    if script.Parent.Switch.Value == false and script.Parent.Cooldown.Value == false then
        a = Instance.new("Sound",char.Torso)
        a.SoundId = "http://www.roblox.com/asset/?id=120550472"
        a:Play()
        wait(2)
        a:Destroy()
    end
end

script.Parent.MouseButton1Up:connect(playleSound)

Answer this question