Enemies don't get push back

I want the enemies to get push back when player dash in the air and hit the enemy but when i try it nothing happen

here is the script, im very new to scripting so the script might look very bad:

local UIS = game:GetService("UserInputService")
local TagService = game:GetService("CollectionService")
local Character = game.Players.LocalPlayer.Character
local Humanoid = script.Parent.Parent.Humanoid

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RaycastHitbox = require(ReplicatedStorage.RaycastHitboxV4)
local newHitbox = RaycastHitbox.new(script.Parent.Parent:WaitForChild("HumanoidRootPart"))

local DashParticle = script.Parent.Parent:WaitForChild("UpperTorso").DashParticle
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = {script.Parent.Parent}
Params.FilterType = Enum.RaycastFilterType.Blacklist
newHitbox.RaycastParams = Params

local Canrun = true

function Dash (Input)
	if Input.UserInputType == Enum.UserInputType.Keyboard and Canrun == true then
		if Input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0 and Humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
			Canrun = false
			DashParticle.Enabled = true
			Humanoid.JumpPower = 0
			script:SetAttribute("Dashing",true)
			local v = Instance.new("BodyPosition")
				v.MaxForce = Vector3.new(99999,0,0)
				v.P = 30000
				v.D = 2000
				v.Position = (Character.Head.CFrame*Vector3.new(0,0,-130)) 
				v.Parent = Character.Head
				
			wait(0.001)
			v:Destroy()
			wait(0.5)
			DashParticle.Enabled = false
			Canrun = true
			script:SetAttribute("Dashing",false)
			Humanoid.JumpPower = 70
		elseif Input.KeyCode == Enum.KeyCode.LeftShift and Humanoid.MoveDirection.Magnitude > 0 and Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
			Canrun = false
			DashParticle.Enabled = true
			script:SetAttribute("Dashing",true)
			newHitbox:HitStart()
			local v = Instance.new("BodyPosition")
				v.MaxForce = Vector3.new(70000,0,0)
				v.P = 30000
				v.D = 2000
				v.Position = (Character.Head.CFrame*Vector3.new(0,0,-130)) 
				v.Parent = Character.Head
			
			newHitbox.OnHit:Connect(function(hit, humanoid)
					local Bv = Instance.new("BodyPosition")
					Bv.MaxForce = Vector3.new(90000,90000,90000)
					Bv.P = 30000
					Bv.D = 2000
					Bv.Position = hit.Parent.Head.CFrame.LookVector * -100
					Bv.Parent = hit.Parent.Head
				
					print(hit)
					
					humanoid:TakeDamage(5)
				end)

			wait(0.001)
			v:Destroy()
			wait(0.5)
			DashParticle.Enabled = false
			Canrun = true
			script:SetAttribute("Dashing",false)
			newHitbox:HitStop()
		end
	end
end

function KeyPressEnded (Input)
	
end

UIS.InputBegan:Connect(Dash)
UIS.InputEnded:Connect(KeyPressEnded)

the section that suppose to push the enemies:

newHitbox.OnHit:Connect(function(hit, humanoid)
					local Bv = Instance.new("BodyPosition")
					Bv.MaxForce = Vector3.new(90000,90000,90000)
					Bv.P = 30000
					Bv.D = 2000
					Bv.Position = hit.Parent.Head.CFrame.LookVector * -100
					Bv.Parent = hit.Parent.Head
				
					print(hit)
					
					humanoid:TakeDamage(5)
				end)

BodyPosition is deprecated, so It isn’t reliable. Try using AlignOrientation

Try use body velocity. Tell me if this works

it didn’t work unfortunately, i tried

i have finally got it to work by using remoteEvent to change the custom attribute on the server and use collection service to check if that attribute is set to true, it will push the enemy backward so i wouldn’t have the same script in all the characters, it might not be the best solution but it work

i still have no idea why the original code doesn’t work but thanks you guys for trying to helping me out (sorry if it doesn’t make sense, english is not my first language)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.