im trying to make an avalanche that moves left and right in a loop, and i saw bodyvelocities and made a jump pad and it worked, but with avalanches i cant get them working.
I just saw the initial while true do and responded accordingly, on a second note those yielding commands should be replaced with task.wait(x) as they are more accurate.
Never opt for while (yield) do, both because it makes your code less readable, and because it forces yield at the start of every iteration giving you less control.
For the sake of literacy you should exclusively be using while true do unless you are actually expecting your conditional circumstance to break your loop.
OP what actual functionality are you trying to achieve? Do you want the part to bounce around?
local bodyForce = script.Parent.BodyForce
local magnitude = 100
local left = Vector3.new(-1, 0, 0) * magnitude
local right = Vector3.new(1, 0, 0) * magnitude
while task.wait(5) do
bodyForce.Force = bodyForce.Parent.CFrame:vectorToWorldSpace(left)
task.wait(5)
bodyForce.Force = bodyForce.Parent.CFrame:vectorToWorldSpace(right)
end
no im trying to make an avalanche move left and right forever but smoothly and i didnt want to learn tweening and tweenservice so i decided to use bodyvelocity
Is the Part you are trying to move the one with the script in it?
It would be good if you showed a picture of what you are trying to accomplish.
An Anchored Part with BodyVelocity in it acts like a conveyor belt and will move Parts that sit on top of it.
What is the Friction Property (in the BasePart | Roblox Creator Documentation) of the Part(s) set at? If it’s too high then you are probably going to need a lot of Force to move it. Same with the Part(s) the first Part(s) are sitting on.
p = script.Parent -- our part
v = script.Parent.BodyVelocity -- our body mover
local current_force = Vector3.new(-1, 0, 0) -- vector variable to toggle
local amplifier = 50 -- magnitude
local default_time = .25 -- time per velocity change
while true do
current_force = current_force * -1
v.Velocity = current_force*amplifier
task.wait(default_time)
v.Velocity = Vector3.new(0, 0, 0)
end
Keep in mind that BodyVelocity does not naturally slow itself down, so ideally you would manually reset your part’s velocity after every iteration (otherwise I think it maintains its past velocity as a BasePart & is somewhat fighting against it, which is why it might behave differently than you want it to).
Also worth mentioning that if you’re planning to do this with a lot of parts, handle it all under the same thread.