Hi,
I made a sword but there is a problem : the “Touched” event doesn’t work when my animation is playing, and the sword goes through the Dummy.
I’ve tested with others animations and the script works but I don’t know why it don’t works with this one.
Video :
Script :
local sword = script.Parent
local Attack = script.Parent:WaitForChild("Attack")
local handle = script.Parent:WaitForChild("Handle")
local character
local trail = handle.Trail
local combo = 1
local canDamage = false
local cooldown = false
local cooldownTime = .5
local debounce = false
local Equipped = false
local countForReset = 0
local timeBeforeReset = 4
local hitDebounce = false
local AnimIdle = handle.Idle
local AnimWalk = handle.Walking
local AnimUnsheate = handle.Unsheate
local AnimSheate = handle.Sheate
local AnimSlash1 = handle.Slash1
local AnimSlash2 = handle.Slash2
local AnimSlash3 = handle.Slash3
local AnimSlash4 = handle.Slash5
local AnimSlash5 = handle.Slash5
local IdleAnimTrack
local WalkingAnimTrack
local AnimTrack
local UnsheateAnimTrack
local SheateAnimTrack
local waitTime = 1
script.Parent.Equip.OnServerEvent:Connect(function(plr)
character = plr.Character
Equipped = true
if SheateAnimTrack then
if SheateAnimTrack.IsPlaying == true then
SheateAnimTrack.Stopped:Wait()
end
end
character.HumanoidRootPart.Anchored = true
UnsheateAnimTrack = character.Humanoid:LoadAnimation(AnimUnsheate)
UnsheateAnimTrack:Play()
UnsheateAnimTrack.Stopped:Wait()
character.HumanoidRootPart.Anchored = false
end)
sword.Unequipped:Connect(function()
Equipped = false
SheateAnimTrack = character.Humanoid:LoadAnimation(AnimSheate)
character.HumanoidRootPart.Anchored = true
SheateAnimTrack:Play()
SheateAnimTrack.Stopped:Wait()
character.HumanoidRootPart.Anchored = false
if IdleAnimTrack then
IdleAnimTrack:Stop()
end
if WalkingAnimTrack then
WalkingAnimTrack:Stop()
end
end)
script.Parent.StartRun.OnServerEvent:Connect(function()
if Equipped == true then
if IdleAnimTrack then
IdleAnimTrack:Stop()
end
if WalkingAnimTrack == nil then
WalkingAnimTrack = character.Humanoid:LoadAnimation(AnimWalk)
WalkingAnimTrack:Play()
WalkingAnimTrack:AdjustSpeed(2)
elseif WalkingAnimTrack.IsPlaying == false then
WalkingAnimTrack = character.Humanoid:LoadAnimation(AnimWalk)
WalkingAnimTrack:Play()
WalkingAnimTrack:AdjustSpeed(2)
end
end
end)
script.Parent.EndRun.OnServerEvent:Connect(function()
if Equipped == true then
if WalkingAnimTrack then
WalkingAnimTrack:Stop()
end
if IdleAnimTrack == nil then
IdleAnimTrack = character.Humanoid:LoadAnimation(AnimIdle)
IdleAnimTrack:Play()
elseif IdleAnimTrack.IsPlaying == false then
IdleAnimTrack = character.Humanoid:LoadAnimation(AnimIdle)
IdleAnimTrack:Play()
end
end
end)
handle.Touched:Connect(function(hit)
print(canDamage)
if canDamage == true then
if hit.Parent:FindFirstChildOfClass("Humanoid") then
if hit.Parent ~= character then
canDamage = false
hit.Parent.Humanoid:TakeDamage(20)
end
end
end
end)
sword.Activated:Connect(function()
if debounce == false then
debounce = true
if cooldown == false then
if WalkingAnimTrack then
WalkingAnimTrack:Stop()
end
if IdleAnimTrack then
IdleAnimTrack:Stop()
end
canDamage = true
trail.Enabled = true
character.HumanoidRootPart.Anchored = true
if combo == 1 then
AnimTrack = character.Humanoid:LoadAnimation(AnimSlash1)
AnimTrack:Play()
wait(waitTime)
countForReset = 0
combo = 2
elseif combo == 2 then
AnimTrack = character.Humanoid:LoadAnimation(AnimSlash2)
AnimTrack:Play()
wait(waitTime)
countForReset = 0
combo = 3
elseif combo == 3 then
AnimTrack = character.Humanoid:LoadAnimation(AnimSlash1)
AnimTrack:Play()
wait(waitTime)
countForReset = 0
combo = 4
elseif combo == 4 then
AnimTrack = character.Humanoid:LoadAnimation(AnimSlash2)
AnimTrack:Play()
wait(waitTime)
countForReset = 0
combo = 5
elseif combo == 5 then
AnimTrack = character.Humanoid:LoadAnimation(AnimSlash5)
AnimTrack:Play()
wait(2.2)
countForReset = 0
combo = 1
end
end
wait(waitTime)
trail.Enabled = false
character.HumanoidRootPart.Anchored = false
debounce = false
canDamage = false
IdleAnimTrack:Play()
end
end)
while wait(1) do
if countForReset < timeBeforeReset then
countForReset += 1
else
combo = 1
countForReset = 0
end
end
(I know there are some useless variables but I don’t think they are the problem)
Please tell me if you have any idea about why this happens