https://www.youtube.com/watch?v=7Cf5Olp3tJ0
The Sword was suposed to damage any humanoid that it touches on the first swing but the damage function is being activated with a delay for some reason and it is making it only damage things ontouch after the animation is done.
The Code:
if keyPressed == Enum.KeyCode.Z and Toggled == true and AnimOn == false and ZAttackCD == true then AnimOn = true ZAttackCD = false Humanoid.WalkSpeed = 0 ZAttack:Play() wait(0.25) TParts.Trail.Enabled = true local Conn Conn = TParts.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then if not hit.Parent.Humanoid:FindFirstChild("BValue") then local dtag = BValue:Clone() dtag.Parent = hit.Parent.Humanoid hit.Parent.Humanoid:TakeDamage(15) game:GetService("Debris"):AddItem(dtag,1) wait(1) Conn:Disconnect() end end end) wait(0.85) TParts.Trail.Enabled = false ZAttack.Stopped:Wait() AnimOn = false Humanoid.WalkSpeed = WalkSpeed wait(10) ZAttackCD = true
Summing up:I want to make it so the sword damages while the char plays the animation of the first swing, not after nor before.
Any help would be appreciated, thanks.
Hey! Did you know that you could put events in the animation editor?
You can use this feature to make this line of script work:
canhit = true AnimationTrack:GetMarkerReachedSignal("animationName"):Connect(function(argument) sword.Touched:Connect(function(hit) if canhit == true then hit.Parent:FindFirstChild("Humanoid"):TakeDamage(15) canhit = false else print("already hit once") end wait(animation timeout time) canhit = false end
To add an animation event, click the pencil with a + using the roblox animation editor. There, you will set the name and the parameter and the marker will signal the function above when it hits the keyframe you put it at.
Orrrr you can just use this handy module made by Swordphin123
https://devforum.roblox.com/t/raycast-hitbox-module-for-all-your-melee-needs/374482