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:
01 | if keyPressed = = Enum.KeyCode.Z and Toggled = = true and AnimOn = = false and ZAttackCD = = true then |
02 | AnimOn = true |
03 | ZAttackCD = false |
04 | Humanoid.WalkSpeed = 0 |
05 | ZAttack:Play() |
06 | wait( 0.25 ) |
07 | TParts.Trail.Enabled = true |
08 | local Conn |
09 | Conn = TParts.Touched:Connect( function (hit) |
10 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
11 | if not hit.Parent.Humanoid:FindFirstChild( "BValue" ) then |
12 | local dtag = BValue:Clone() |
13 | dtag.Parent = hit.Parent.Humanoid |
14 | hit.Parent.Humanoid:TakeDamage( 15 ) |
15 | game:GetService( "Debris" ):AddItem(dtag, 1 ) |
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:
01 | canhit = true |
02 | AnimationTrack:GetMarkerReachedSignal( "animationName" ):Connect( function (argument) |
03 | sword.Touched:Connect( function (hit) |
04 | if canhit = = true then |
05 | hit.Parent:FindFirstChild( "Humanoid" ):TakeDamage( 15 ) |
06 | canhit = false |
07 | else |
08 | print ( "already hit once" ) |
09 | end |
10 | wait(animation timeout time) |
11 | canhit = false |
12 | 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