I've been working on the script for a while, I kind of know the issue, but I cant quite put my finger on it. Any help would be great.
Tool = script.Parent
char = Tool:FindFirstAncestorWhichIsA("Player").Character
hum = char:WaitForChild("Humanoid")
animfolder = Tool.Anims
slash = animfolder.Slash
idle = animfolder.Idle
equip = animfolder.Equip
unequip = animfolder.Unequip
swordwalk = animfolder.Walk
swordrun = animfolder.Run
playerState = nil
tag = Tool.Tag
slashsound = Tool.Handle.Slash
hitsound = Tool.Handle.Hit
cd = false
equipped = false
function Hit_Target(character, target_humanoid)
--print(character, target_humanoid)
target_humanoid:TakeDamage(20)
hitsound:Play()
end
function Equipped()
equipped = true
walkanim = hum:LoadAnimation(swordwalk)
idleanim = hum:LoadAnimation(idle)
runanim = hum:LoadAnimation(swordrun)
print("Equipped")
end
function Activated()
--print("Slash!")
if cd == false then
cd = true
local animationTrack = hum:LoadAnimation(slash)
idleanim:Stop()
animationTrack:Play(0.3,1,1.5)
slashsound:Play()
Tool.Handle.Touched:Connect(function(hit)
if cd == true then
--print(hit)
local character = hit:FindFirstAncestorWhichIsA("Model")
if character then
if character:FindFirstChildWhichIsA("Humanoid") then
local target_humanoid = character:FindFirstChildWhichIsA("Humanoid")
if tag.Value ~= nil then
print("Already Tagged")
else
tag.Value = target_humanoid
--print(character.Name, target_humanoid.Name)
Hit_Target(character, target_humanoid)
end
end
end
end
end)
wait(1)
cd = false
tag.Value = nil
idleanim:Play()
end
end
function Deactivated()
print("Deactivated")
end
function Unequipped()
equipped = false
print("Unequipped")
idleanim:Stop()
end
Tool.Equipped:Connect(Equipped)
Tool.Activated:Connect(Activated)
Tool.Deactivated:Connect(Deactivated)
Tool.Unequipped:Connect(Unequipped)
while true do
wait(1)
if equipped == true then
print(hum:GetPlayingAnimationTracks())
--for i, v in pairs(hum:GetPlayingAnimationTracks()) do
-- print(i, v)
-- if v.Name ~= playerState then
-- v:Stop()
-- end
--end
local speed = Vector3.new(char.HumanoidRootPart.Velocity.X, 0, char.HumanoidRootPart.Velocity.Z).Magnitude
if speed >= 1 and speed <= 16.1 then
print("Walking")
print(hum:GetPlayingAnimationTracks())
if table.find(hum:GetPlayingAnimationTracks(), "Walk") then
else
idleanim:Stop()
runanim:Stop()
walkanim:Play()
end
playerState = "Walk"
elseif speed == 0 then
print("idle")
print(hum:GetPlayingAnimationTracks())
if table.find(hum:GetPlayingAnimationTracks(), "Idle") then
else
runanim:Stop()
walkanim:Stop()
idleanim:Play()
end
playerState = "Idle"
else
print("Running")
if table.find(hum:GetPlayingAnimationTracks(), "Run") then
else
idleanim:Stop()
walkanim:Stop()
runanim:Play()
end
playerState = "Run"
end
end
end
