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

How do I make an autoclicker cooldown for this script?

Asked by 5 years ago
Edited by Gey4Jesus69 5 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

Okay so basically, I have this script in serverscriptservice:

game.ReplicatedStorage.LightSaberEvent.OnServerEvent:Connect(function(player)
    player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 100000000
    workspace[player.Name].LightSaberv1.ManualActivationOnly = true
    wait(0.3)
    workspace[player.Name].LightSaberv1.ManualActivationOnly = false
end)

and I wanna make an autoclicker cooldown for 5 seconds. The RemoteEvent is: LightSaberEvent

and the replicated storage local script is

script.LightSaberEvent.OnServerEvent:Connect(function()
    game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 100000000
end)

Basically the same thing. The local script for the tool of the lightsaber is :

player = game.Players.LocalPlayer

script.Parent.Activated:Connect(function()
    game.ReplicatedStorage.LightSaberEvent:FireServer()
end)

script.Parent.Equipped:Connect(function()
    game.Workspace[player.Name].LightSaberv1.ManualActivationOnly = false
end)

script.Parent.Unequipped:Connect(function()
    game.Players[player.Name].Backpack.LightSaberv1.ManualActivationOnly = true
end)

Please help me I'm lost in trying to make an auto clicker cooldown script.

0
This is for 5 seconds. After thats done. Then 20 seconds later the same cooldown for 5 seconds should pop up. adssssssssssad 0 — 5y
0
please format your code properly Gey4Jesus69 2705 — 5y
0
how? adssssssssssad 0 — 5y
0
use a debounce 0.0 DeceptiveCaster 3761 — 5y
View all comments (3 more)
0
whats that adssssssssssad 0 — 5y
0
how do you not know what a debounce is? you clearly know how to use remote events and leaderstats DeceptiveCaster 3761 — 5y
0
There you go a link for debounce.. https://developer.roblox.com/articles/Debounce Miniller 562 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
player = game.Players.LocalPlayer
local debounce = 5
local canUse = true

script.Parent.Activated:Connect(function()
    if canUse == true then -- Checking to see if the user can use there tool
        game.ReplicatedStorage.LightSaberEvent:FireServer()
        canUse = false -- Making it so the user can't use it
        spawn(function() -- Making a seperate thread, this way the waiting isn't delayed
            wait(debounce) -- Waiting our 5 seconds (seen via debounce)
            canUse = true -- Making it so the user can activate there tool again
        end)
    end
end)

script.Parent.Equipped:Connect(function()
    game.Workspace[player.Name].LightSaberv1.ManualActivationOnly = false
end)

script.Parent.Unequipped:Connect(function()
    game.Players[player.Name].Backpack.LightSaberv1.ManualActivationOnly = true
end)
1
why is player not a local variable DeceptiveCaster 3761 — 5y
Ad

Answer this question