Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to fix onTouch Function Delay?

Asked by 5 years ago
Edited 5 years ago

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:

01if 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)
View all 27 lines...

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.

1 answer

Log in to vote
0
Answered by
asgm 109
5 years ago
Edited 5 years ago

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:

01canhit = true
02AnimationTrack: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
12end

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

Ad

Answer this question