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

Help with BodyPosition? (moving in a certain direction)

Asked by
Elixcore 1337 Moderation Voter
6 years ago

Hello so I recently tried to make a script that would clone a part in front of u then make it go in the same direction u are facing but I failed and i don't know how to fix it. Part with problem is written in the script with " -- Part with problem" along with explanation

game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAdded:connect(function(chr)
plr.Chatted:connect(function(msg)
if plr.Name == "My username." then 
if msg == "Red" then
    local hi = game.Workspace.AlexTest.boio:Clone()
    hi.Parent = chr
    hi.CFrame = chr.Torso.CFrame * CFrame.new(0,0,-5)
    hi.Orientation = chr.Torso.Orientation - Vector3.new(0,90,0)
    hi.Name = "Red"
    hi.Anchored = false
chr.Humanoid.WalkSpeed = 0
 -- ^ clone the tool, bring it in front of my torso facing the same direction as my torso.

hi.p.Position = Vector3.new(chr.Torso.CFrame * CFrame.new(0,0,-5000)) -- Part with problem.
--https://gyazo.com/bf847c8fdbe6deb1fee00dd9f8e20156 
-- this is what happens.

chr.Humanoid.WalkSpeed = 16

wait(10)
hi:Destroy()

end
end
end)
end)
end)

There are 2 problems.

  1. It's going down but I can't anchor it because it won't move then.
  2. It's not moving in the direction my torso is facing.

Note: hi.p is a BodyPosition.

1 answer

Log in to vote
1
Answered by 6 years ago

You don't wanna use bodyposition to make something move to a specified point, you wanna use bodyvelocity like this

        local bv = Instance.new("BodyVelocity", x) -- x being the part its being parented to    
        bv.MaxForce = Vector3.new(1e8, 1e8, 1e8)
        bv.Velocity = root.CFrame.lookVector * 80 -- root obviously being the players root, youd need to define the players root for this line to work

adding this should make something move forward as a projectile

0
sorry let me rephrase, bodyposition is to pull things towards a specific point, body velocity is to move something forward DeviantProphet 50 — 6y
0
Thank you very much! sorry for the late reply! it works perfectly Elixcore 1337 — 6y
Ad

Answer this question