Hi, so I have a sword with and activating function but it doesn't activate when I walk, is the a roblox glitch or is there something to do with the code?

Code:

wait(1)

script.Parent.Equipped:Connect(function()
	local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
	wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)

--//Attacking Animations\\--
local UserInputService = game:GetService("UserInputService")
local Tool = script.Parent
local CanAttack = true
local Anim_Name = "Attack"
local Audio = script.Parent:WaitForChild("Handle"):WaitForChild("Swing")
local Attack_Animations = script.Parent:WaitForChild("Animations")
local Attack_Num = 1
local blade = script.Parent.DaggerBlade



blade.Touched:Connect(function(hit)
	if CanAttack == false then
		game.ReplicatedStorage.Damage:FireServer(hit)
	end
end)

Tool.Activated:Connect(function()
		local Animation = script.Parent.Parent.Humanoid:LoadAnimation(Attack_Animations[Anim_Name..Attack_Num])
		if CanAttack == true then
            CanAttack = false
			Animation:Play()
			Audio:Play()
			wait(0.6)
			CanAttack = true
			if Attack_Num == 1 then
				Attack_Num = Attack_Num + 1
				else if Attack_Num == 2 then
					Attack_Num = 1
				end
			end
		end
end)

Tool.Deactivated:Connect(function()
	script.Parent.Equipped:Connect(function()
	local idle = script.Parent.Parent.Humanoid:LoadAnimation(script.Parent.Animations.Idle)
	wait(0.1)
idle:Play()
script.Parent.Unequipped:Connect(function()
idle:Stop()
end)
end)
end)

1 comment

0

set animationpriority to action