How can I make this knockback script work?

So I’m trying to make a part knockback players for about a second or two before the force stops being applied. I cannot seem to get this to work heres thee script.

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		part.Parent.Humanoid.Sit = true
		for i, object in pairs(part.Parent:GetChildren()) do 
			if object:IsA("BasePart") then 
				object.Massless = true
			end
		end
		local Speed = 40
		local Force = 100

		local TotalForce = Force

		local KnockBack = Instance.new("BodyVelocity")
		KnockBack.Parent = part.Parent:FindFirstChild("HumanoidRootPart")

		KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
		KnockBack.Velocity = script.Parent.CFrame.LookVector * Speed 
		task.wait(3)
		for i, object2 in pairs(part.Parent:GetChildren()) do 
			if object2:IsA("BasePart") then 
				object2.Massless = false
			end
		end
	end
end)

To make the knockback script work, you gotta set the force to 80,000 to 85,000 or math.huge to make the force to reach it limit

Full script:

script.Parent.Touched:Connect(function(part)
	if part.Parent:FindFirstChild("Humanoid") then
		part.Parent.Humanoid.Sit = true
		for i, object in pairs(part.Parent:GetChildren()) do 
			if object:IsA("BasePart") then 
				object.Massless = true
			end
		end
			
		local Speed = 40
		local Force = math.huge
		local KnockBackDuration = .25

		local TotalForce = Force

		local hrp = part.Parent:WaitForChild("HumanoidRootPart") or part.Parent.PrimaryPart

		coroutine.resume(coroutine.create(function()
			local KnockBack = Instance.new("BodyVelocity")
			KnockBack.Parent = hrp
	
			KnockBack.MaxForce = Vector3.new(TotalForce,TotalForce,TotalForce)
			KnockBack.Velocity = hrp.CFrame.LookVector * -Speed
			task.wait(KnockBackDuration)
			KnockBack:Destroy()
		end))
			
		task.wait(3)
		for i, object2 in pairs(part.Parent:GetChildren()) do 
			if object2:IsA("BasePart") then 
				object2.Massless = false
			end
		end
	end
end)

try making the maxforce into this

Vector3.new(math.huge, math.huge, math.huge)

would that keep that player flying for ages or would it only knockback around 20-30 studs? Because I want it to be around 20-30 studs and when I had the number at 8,000 the player just hit a wall and stayed flying there for ages.

Have you tried lowering the duration or speed, but also have a high force like math.huge?

1 Like

It will let the player fly for .25 seconds then destroy the knockback force.

1 Like

my bad I didnt read the full script but I see now and I can edit it to what I need thank you!