Bodyvelocity not working

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.


heres literally everything you need for solving this issue

while true do
	script.Parent.bodyVelocity.Velocity = (script.Parent.CFrame.LookVector * 20)
	task.wait(5)
	script.Parent.bodyVelocity.Velocity = (script.Parent.CFrame.LookVector * 20)
	task.wait(5)
end

Avoid using while true do as well, since it can cause crashes in more complex scripts, opt for while task.wait() do.

while true do is completely fine if there’s any kind of yield inside the loop while task.wait() do would just unnecessary yield in this case.

1 Like

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.

oof, the issue still persists its not going left or right

ok sdhufodglfdhmdndhkfgnhkmfhkfdhmk

while task.wait(5) do
	script.Parent.Velocity = Vector3.new(100, 0, 0)
	task.wait(5)
	script.Parent.Velocity = Vector3.new(-100, 0, 0)
end

Place inside the bodymover itself. Make sure the avalanche part isn’t anchored too.

it dosent work and the avalanche wasnt anchored

Try a really large Vector3 value, like Vector3.new(99999, 99999, 99999).

Also modify the other properties of the bodyvelocity too.

dosent work and i think the settings are already good as you see
image
(ignore the velocity that would obviously be changed by the script)

Try using a bodymover or a bodyforce instance instead. Make sure the death script isn’t causing any unwanted effects on the part too.

ok (300000000000000000 ch ars)

seems more complex but im making the script

image
didnt work

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?

code:

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

i found a way better idea, ill use for i = 1,100 instead. if it still dosent work ill try to stick with bodyvelocity again

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.

This is how you could do it with a BodyVelocity:

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.

I’ll try it, if it works I’ll mark your post as solution