Knockback when hit by car

I’m working on a knockback system for when a player gets hit by a car. Im using Magnitude with Touched and it glitches out from time to time. If anyone has insight on a script that uses car knockback and or if you know some games that use character knockback from cars so I can contact the owner, please let me know.

part = script.Parent
local ragdoll = require(game:GetService("ServerScriptService").Main.Ragdoll)
local kb = require(game.ServerScriptService.Main.Knockback)

local db = {}

local knockback = script.Parent:GetAttribute("Knockback")
local speed = script.Parent:GetAttribute("MaxSpeedToDoDamage")
part.Touched:Connect(function(hit)
	if table.find(db, hit.Parent) then return end
	local hum = hit.Parent:FindFirstChild("Humanoid")
	if hum then
		if part.AssemblyLinearVelocity.X > speed or part.AssemblyLinearVelocity.Y > speed or part.AssemblyLinearVelocity.Z > speed then
			table.insert(db, hit.Parent)
			script["Explosion Sound"]:Play()
			kb.Start(hit.Parent, (hit.Parent.HumanoidRootPart.Position - part.Position).Unit * Vector3.new(200,0,200) + Vector3.new(0, 50), (script.Parent.Velocity - hit.Velocity).magnitude*knockback)
			ragdoll.Start(hit.Parent)
			task.wait(5)
			table.remove(db, table.find(db, hit.Parent))
			ragdoll.Stop(hit.Parent)
		end
	end
end)

What’s the script for your knock back?

1 Like

I updated the post with the code,

Maybe it’s the knock back module itself, I don’t see anything bad here.

if the issue you’re facing is late detection or no detection at all, try making a big part that surrounds the vehicle with cancollide off, and use that as a bigger hitbox. you can use dot product or local space CFrames to determine whether the collision occurs at the front of the car or not for a better hit detection because fast moving objects are very wonky.