Damage Script:
local player = game.Players.LocalPlayer local handle = script.Parent.Handle local debounce = false handle.Touched:Connect(function(hit) if not debounce and hit and hit.Parent.Humanoid then debounce = true hit.Parent.Humanoid:TakeDamage(25) wait(15) debounce = false end end)
=====================================================================================================================================================
If this is about causing knockback in a player, or an NPC you would clone from storage, something I like to do in this case is to have a bodyforce in the primarypart of the player or NPC before it gets put into the workspace. That way, you just access the NPC or player's bodyForce and apply a force to it whenever you want.
So it seems as if you are attacking NPCs, so to have a script place a bodyVelocity in an NPC the script would be like:
workspace.ChildAdded:Connect(function(child) if child.Name == "whatever the bodyforce is going to be in" then--this would be the model of the NPC local bv = Instance.new("BodyVelocity") bv.Parent = child.PrimaryPart end end)
Your script would look like:
local player = game.Players.LocalPlayer local handle = script.Parent.Handle local debounce = false local playerPos = player.PrimaryPart.CFrame handle.Touched:Connect(function(hit) if not debounce and hit and hit.Parent.Humanoid then debounce = true local hitPos = hit.Parent.PrimaryPart.CFrame hit.Parent.Humanoid:TakeDamage(25) hit.Parent.PrimaryPart.bodyForce.Force = (playerPos-hitPos).unit*-3 --negative so it goes away from you wait(.5) hit.Parent.PrimaryPart.bodyForce.Force = Vector3.new(0,0,0) wait(14.5)--keeps the original 15 seconds, while allowing the force to stop after .5 seconds debounce = false end end)
To explain the bodyForce line, it makes it so that Point A is you and Point B is the enemy, but it is multiplied by a negative number so that the enemy is knocked away from you while being in line with you.
To visualize this, you are the end of a stick, the enemy is the fulcrum (the point a lever rotates on) and if we multiplied the force by a positive number, the enemy would go towards you, if we multiply it by a negative number, the enemy goes to the opposite end of the stick.