Trouble with ability script

Hello fellow deform users! For an unknown reason my simple ability script refuses to work properly, and I want it to work properly, if you somehow haven’t already noticed. The problem with the script is that it has no cooldown, yes I have tried debugging it but I have found no solution so far.

here is the server script.

local plrs = game:GetService("Players")
local plr = plrs:GetPlayers()[1] or plrs.PlayerAdded:Wait()
local tool1 = script.Parent


tool1.Equipped:Connect(function()
	
	local db = false
	local Drinkanim = plr.Character:WaitForChild("Humanoid"):LoadAnimation(tool1.DrinkAnim)


	if db == true then	
		tool1.Parent = plr.Backpack	
		return
	end
	
	
	if db == false then	
		
		db = true
		Drinkanim:Play()
		
		task.delay(.9, function()	
			
			tool1.DrinkSound:Play()	
		end)
		
		tool1.Parent.Humanoid.WalkSpeed = 5
		
		task.wait(1.2)
		
		tool1.Parent.Humanoid.WalkSpeed = 35
		tool1.Parent = plr.Backpack
		tool1.Handle.Transparency = 1
		
		task.wait(5)
		
		plr.Character.Humanoid.WalkSpeed = 25
		
		task.wait(15)
		
		tool1.Handle.Transparency = 0
		db = false
	end
end)

All help is appreciated!

The first area I feel would be worth checking is how the ability is activating. From what I can tell, it seems you’ve made the tool activate when the player equips it. This on its own isn’t a problem, but putting db into that connected function is, as it will instantiate as false. That is, db is set to false every time the player equips the tool, thus always allowing the cooldown to take effect. To fix this, I’d try moving db out of that function.

Oh. Well that seems simpler than I thought it would. Thx!

I’ll test it when I get the chance!

Edit: worked! Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.