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:
01 | local handle = script.Parent.Handle |
02 | local db = true |
03 |
04 | handle.Touched:Connect( function (plrhit) |
05 | if plrhit.Parent:FindFirstChild( "Humanoid" ) and db = = true then |
06 | db = false |
07 | local BodyAng = Instance.new( "BodyVelocity" ) |
08 | BodyAng.Velocity = Vector 3. new(handle.CFrame.LookVector.X * 20 ,handle.CFrame.LookVector.Y * 20 ,handle.CFrame.LookVector.Z * 20 ) |
09 | BodyAng.MaxForce = Vector 3. new( 500000 , 500000 , 500000 ) |
10 | BodyAng.Parent = plrhit.Parent.HumanoidRootPart |
11 | wait( 2 ) |
12 | db = true |
13 | plrhit.Parent.HumanoidRootPart.BodyVelocity:Destroy() |
14 | end |
15 | 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:
01 | local handle = script.Parent.Handle |
02 | local character = -- here you get the character of the tool user, you should know how |
03 | local db = true |
04 |
05 | handle.Touched:Connect( |
06 | function (plrhit) |
07 | if not plrhit.Parent.Humanoid or not db then |
08 | return |
09 | end |
10 |
11 | db = false |
12 | local BodyAng = Instance.new( "BodyVelocity" ) |
13 | BodyAng.Velocity = character.HumanoidRootPart.CFrame.LookVector * 20 |
14 | BodyAng.MaxForce = Vector 3. new( 500000 , 500000 , 500000 ) |
15 | BodyAng.Parent = plrhit.Parent.HumanoidRootPart |
16 | wait( 2 ) |
17 | db = true |
18 | plrhit.Parent.HumanoidRootPart.BodyVelocity:Destroy() |
19 | end |
20 | ) |
If is it helpful, please accept the answer :) I'm glad to help!