Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)
-----------------

This discussion is preserved as it was. New answers, comments, and votes are closed.