Need help with the Activated event for this tool

Every time I click on the tool the script doesn’t function. I’m not really sure why this will not work. No errors appear when the tool is clicked. Here’s the script:

local Player = game:GetService("Players").LocalPlayer
local ManaStat = Player:WaitForChild("StatsData")["Mana"]
local Cooldown = false 
Variable = 0


script.Parent.Activated:Connect(function()
	if Cooldown == true then return end 
	Cooldown = true 
	
	local Animation = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("VacuusCasting")) 
	
	-- THIS CODE WILL PLAY IF THE PLAYER CAST IT RIGHT
	Animation:Play() 
	wait(1.3) 
	Player.Character.Humanoid.WalkSpeed = 4 	
	
	-- LOOPS THE ATTACK 100 TIMES
	for i = 1,100 do
		wait()
		if Variable == 1 then return end
		game.ReplicatedStorage["Incantations [EVENTS]"]:WaitForChild("VacuusEvent"):FireServer()
			
	-- IF 'i' IS 100 THEN
		if i == 100 then
			Animation:Stop(0.5)
			Player.Character.Humanoid.WalkSpeed = 16
		end
	end	
	Cooldown = false 
end)

script.Parent.Unequipped:Connect(function()
	Variable = 1
end)

promblem

1 Like

You forgot to add an Equipped Event. Basically you check if Variable is 1 then it will “cancel” the effect. Your Unequipped event sets it to 1 but nothing sets it back to 0

You can’t actually link Spaced variables.
If you wanted to link spaced variables,
Use :WaitForChild().

local Player = game:GetService("Players").LocalPlayer
local ManaStat = Player:WaitForChild("StatsData")["Mana"]
local Cooldown = false 
Variable = 0


script.Parent.Activated:Connect(function()
	if Cooldown == true then return end 
	Cooldown = true 
	
	local Animation = Player.Character:WaitForChild("Humanoid"):LoadAnimation(script:WaitForChild("VacuusCasting")) 
	
	-- THIS CODE WILL PLAY IF THE PLAYER CAST IT RIGHT
	Animation:Play() 
	wait(1.3) 
	Player.Character.Humanoid.WalkSpeed = 4 	
	
	-- LOOPS THE ATTACK 100 TIMES
	for i = 1,100 do
		wait()
		if Variable == 1 then return end
		game.ReplicatedStorage:WaitForChild("Incantations [EVENTS]"):WaitForChild("VacuusEvent"):FireServer()
			
	-- IF 'i' IS 100 THEN
		if i == 100 then
			Animation:Stop(0.5)
			Player.Character.Humanoid.WalkSpeed = 16
		end
	end	
	Cooldown = false 
end)

script.Parent.Unequipped:Connect(function()
	Variable = 1
end)

This isn’t true. Using square brackets works just fine.

1 Like

this doesn’t work. Activate function doesn’t work itself

If the tool does not have a handle; make sure to disable the RequiresHandle property on the tool. This was an issue to me yesterday and by doing this it was resolved.