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

I made this cool down in a local script for my function,Why wont my cool down in my script work???

Asked by 4 years ago

So its a gui local script but the cool down wont work what have i dont wrong???

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local button_clicked = false
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = true
    connection:Disconnect()
    connection = true
end)

local readz = true

local function punch(connection,readz, gameProcessed)
    if connection ~= false and readz then
        connection = false
        punchEvent:FireServer()
        readz = false 
        wait(0.5)
        connection = true
        readz = true
       print("clicked!!")
    end
end
script.Parent.MouseButton1Down:Connect(punch)
-----------------

1 answer

Log in to vote
0
Answered by 4 years ago

I think it's because in the punch() function you want the arguments: connection, readz and gameProcessed but they are not given when you run the function, they are nil. I think you want to check if the connection variable from line 5 is true or false. Try to remove the arguments inside the function. It should look like this:

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local punchEvent = ReplicatedStorage:WaitForChild("PunchEvent")
local button_clicked = false
local connection
connection = script.Parent.Activated:Connect(function()
    button_clicked = true
    connection:Disconnect()
    connection = true
end)

local readz = true

local function punch() --This line was changed
    if connection ~= false and readz then
        connection = false
        punchEvent:FireServer()
        readz = false 
        wait(0.5)
        connection = true
        readz = true
       print("clicked!!")
    end
end
script.Parent.MouseButton1Down:Connect(punch)
-----------------
Ad

Answer this question