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

Why does the script break on this line, and can I make it work while having ("Cooldown = false")?

So I have a localscript inside a tool and basically whenever you click with the tool equipped its supposed to fire a remote event and run an animation while having a value = false. The tool works fine without the if Tool.Handle.Cooldown == false then but I want it to make the code run if Cooldown = false and not make it run if Cooldown = true. Im a bit of a noob at scripting so if its obvious I probably wont know


local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Attack = ReplicatedStorage:WaitForChild("OnAttackSword")
local char = plr.Character
local Tool = script.Parent

Tool.Activated:Connect(function()
	
	if Tool.Handle.Cooldown == false then -- this line breaks the entire script
		print("Stone Sword was Activated")
		game.ReplicatedStorage:FindFirstChild("OnAttackSword"):FireServer(char)
		local animation = plr.Character.Humanoid:LoadAnimation(script.Parent.Attack1)
		animation:Play()
	end

end)

And yes, I checked if the value was false before running it

1 comment

0

What is Tool.Handle.Cooldown? Is it a Value? If so, try Tool.Handle.Cooldown.Value

1 answer

✓ Accepted answer

#try

local plr = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Attack = ReplicatedStorage:WaitForChild("OnAttackSword")
local char = plr.Character
local Tool = script.Parent

Tool.Activated:Connect(function()

    if Tool.Handle.Cooldown.Value == false then -- this line breaks the entire script
	Tool.Handle.Cooldown.Value = true
        print("Stone Sword was Activated")
        game.ReplicatedStorage:FindFirstChild("OnAttackSword"):FireServer(char)
        local animation = plr.Character.Humanoid:LoadAnimation(script.Parent.Attack1)
        animation:Play()
	wait(5) -- change 5 to how much time you want the cooldown to be 'o'
	Tool.Handle.Cooldown.Value = false
    end

end)

if it still doesn't work, dm me on discord #Blue Duck#8344

1 comment

0

It was late and I forgot the (.Value), but thanks for making a cooldown because this new cooldown is better than an old one I made

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