Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

LookVector not facing forward?

Asked by 4 years ago

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:

01local handle = script.Parent.Handle
02local db = true
03 
04handle.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 = Vector3.new(handle.CFrame.LookVector.X * 20,handle.CFrame.LookVector.Y * 20,handle.CFrame.LookVector.Z * 20)
09        BodyAng.MaxForce = Vector3.new(500000,500000,500000)
10        BodyAng.Parent = plrhit.Parent.HumanoidRootPart
11        wait(2)
12        db = true
13        plrhit.Parent.HumanoidRootPart.BodyVelocity:Destroy()
14    end
15end)

Any help would be appreciated!

1 answer

Log in to vote
3
Answered by
nievadev 112
4 years ago
Edited 4 years ago

The problem is that you are using the handle's CFrame instead of the Player.Character.HumanoidRootPart's one.

This code would fix it:

01local handle = script.Parent.Handle
02local character = -- here you get the character of the tool user, you should know how
03local db = true
04 
05handle.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 = Vector3.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!

1
Works perfectly. Thank you! TheEggsquidzidBoi 38 — 4y
Ad

Answer this question