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

How do I make an autoclicker cooldown for this script?

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.

7 comments

0

This is for 5 seconds. After thats done. Then 20 seconds later the same cooldown for 5 seconds should pop up.

0

please format your code properly

0

how?

0

use a debounce 0.0

0

whats that

0

how do you not know what a debounce is? you clearly know how to use remote events and leaderstats

0

There you go a link for debounce.. https://developer.roblox.com/articles/Debounce

1 answer

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 comment

1

why is player not a local variable

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