Tool will not pick up inputs

So, I’ve been looking around for a while looking for a solution and to be fair, I’m puzzled. All my other Roblox tools work perfectly fine when I use the Activated event, but now, it seems like this tool just won’t pick up any inputs at all. I click and instead of it ever activating, it never does. I try manual activation with the Activate function but that doesn’t work either. It’s not a problem with my functions either, because I can call those directly and it works. I haven’t seen anyone else have the problem so I’m unsure if there’s something wrong with my game.

Code:
local players = game:GetService(“Players”)
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
while character.Parent ~= workspace do
if character.Parent ~= workspace then
character = player.Character or player.CharacterAdded:Wait()
end
game:GetService(“RunService”).RenderStepped:Wait()
end
local humanoid = character:WaitForChild(“Humanoid”)

local slash = Instance.new("Animation")
slash.AnimationId = "rbxassetid://6167663786"
local slashAnim = humanoid:LoadAnimation(slash)

local cooldown = 0.4
local currentlyAttacking = false

local function attack()
	currentlyAttacking = true
	slashAnim:Play()
	wait(0.3)
	currentlyAttacking = false
	print("attacked")
end

local function checkCD()
	if not currentlyAttacking and cooldown == 0 then
		attack()
		cooldown = 0.4
		print("check worked")
	end
	print("activated")
end

while true do
	wait(0.1)
	print(cooldown)
	if cooldown > 0 and not currentlyAttacking then
		cooldown -= 0.1
	elseif cooldown < 0 then
		cooldown = 0	
	end
end

script.Parent.Activated:Connect(checkCD)

(Note, this is a local script inside of a tool)

2 Likes

The code after the while loop won’t run because the while loop never stops. Put the .Activated event before the loop.

script.Parent.Activated:Connect(checkCD)

while true do
	wait(0.1)
	print(cooldown)
	if cooldown > 0 and not currentlyAttacking then
		cooldown -= 0.1
	elseif cooldown < 0 then
		cooldown = 0	
	end
end
1 Like
while true do
	wait(0.1)
	print(cooldown)
	if cooldown > 0 and not currentlyAttacking then
		cooldown -= 0.1
	elseif cooldown < 0 then
		cooldown = 0	
	end
end

as @heII_ish said the loop will stop the rest of the code from executing to solve this you need to use a coroutine

coroutine.wrap(function()
--while loop goes here
end)()

this will allow the loop to be run without interrupting the rest of the code

1 Like