Punch effect on NPC does not synch right with impact

I am working on a system for a redo of one of my games, where NPCs act as “droppers” where they hit a punching bag, and the owner gets cash.

It’s going well, until I tried adding a particle effect to the hand of the NPC, that would get enabled when the hand hits the punching bag for an effect. In the below video, you can see the effect either does not get enabled, or, if it does, it plays way after the NPC has had the bag already.

How do I fix this?

Below are the values for the particle:

Here is the code for the system (so far):

local hum = script.Parent.Humanoid
local aID = script.Parent:GetAttribute("id")
local animation = hum.Parent:FindFirstChild("animation") or Instance.new("Animation",hum.Parent)
animation.AnimationId = "rbxassetid://"..aID
local animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator",hum)
local animationTrack = animator:LoadAnimation(animation)
local goal = {}
goal.StudsOffsetWorldSpace = Vector3.new(0,3,0)
local ts = game:GetService("TweenService")
local info = TweenInfo.new(1.5, Enum.EasingStyle.Quart)

script.Parent.RightHand.Touched:Connect(function(otherPart: BasePart)  
	if otherPart.BrickColor == BrickColor.new("Dusty Rose") then
		script.Parent.RightHand.RightGripAttachment.punch.Enabled = true
	end
end)

while wait(1) do
	local gui = script.earnings:Clone()
	animationTrack:Play()
	gui.Parent = script.Parent.Head
	gui.Adornee = script.Parent.Head
	gui.Enabled = true
	local success, response = pcall(function() 
		local tweenGUI = ts:Create(gui, info, goal)
		tweenGUI:Play()
		tweenGUI.Completed:Wait()
	end)
	if success then
		print("hi")
	else
		print(response)
	end
	script.Parent.RightHand.RightGripAttachment.punch.Enabled = false
	gui:Destroy()
end

The code is messy, I know, but this is early development and I just need to get a working prototype working

1 Like

Look into Animation Events

2 Likes

I am unsure of if this would help. The “Enabled” property of the particle gets turned to true immediately as a hit is confirmed, but the visualization of said effect doesn’t occur until another second or so after.

1 Like

you’d want to check if the hand is touching the bag when the animation event fires, you can do this via rightHand:GetTouchingParts()

also, do particleEmmiter:Emit(1)

2 Likes

Thank you! It works perfectly now.