I'm making a tool where if you hit someone, the player who got hit would be sent in the opposite direction, but it's sending the player sideways. Here's the code:
local handle = script.Parent.Handle local db = true handle.Touched:Connect(function(plrhit) if plrhit.Parent:FindFirstChild("Humanoid") and db == true then db = false local BodyAng = Instance.new("BodyVelocity") BodyAng.Velocity = Vector3.new(handle.CFrame.LookVector.X * 20,handle.CFrame.LookVector.Y * 20,handle.CFrame.LookVector.Z * 20) BodyAng.MaxForce = Vector3.new(500000,500000,500000) BodyAng.Parent = plrhit.Parent.HumanoidRootPart wait(2) db = true plrhit.Parent.HumanoidRootPart.BodyVelocity:Destroy() end end)
Any help would be appreciated!
The problem is that you are using the handle's CFrame instead of the Player.Character.HumanoidRootPart's one.
This code would fix it:
local handle = script.Parent.Handle local character = -- here you get the character of the tool user, you should know how local db = true handle.Touched:Connect( function(plrhit) if not plrhit.Parent.Humanoid or not db then return end db = false local BodyAng = Instance.new("BodyVelocity") BodyAng.Velocity = character.HumanoidRootPart.CFrame.LookVector * 20 BodyAng.MaxForce = Vector3.new(500000, 500000, 500000) BodyAng.Parent = plrhit.Parent.HumanoidRootPart wait(2) db = true plrhit.Parent.HumanoidRootPart.BodyVelocity:Destroy() end )
If is it helpful, please accept the answer :) I'm glad to help!