Better way of scripting a conveyor belt?

Hi! Some time ago I made some conveyor belts for my game CaseOh’s Basics. I just want to ask a question. Is there a better way of doing this? Like a way to cause less lag or is there none?

Here is the script:

game:GetService("RunService").Heartbeat:Connect(function()
	if script.Parent.On.Value==false then
		script.Parent.Beam.TextureSpeed=0.1
script.Parent.Velocity = script.Parent.CFrame.lookVector *8 -- Multiplys the bricks velocity by 15, which causes it to move bricks that land on it.
	else
	-- here we do the same thing but backwards.
		script.Parent.Beam.TextureSpeed=-0.1
		script.Parent.Velocity = script.Parent.CFrame.lookVector *-8
	end
end)

help

1 Like

can’t you just set the part’s AssemblyLinearVelocity to a value of choice, and then anchor the part? since the assembly is technically moving, but anchored it would move any object touching it instead.

2 Likes
while true do 
script.Parent.Velocity = script.Parent.CFrame.lookVector *5
wait(0.1)
end

I use that, I have no other ideas how to cause less lag.

2 Likes

You don’t need to set it in a loop.
Just set it once, and then detect for the change in the direction, and only set it again, when the direction switch is changed.

3 Likes

try this, obviously you will have to adjust it for your game because it’s not exact :smile:


local conveyor = script.Parent
conveyor.Velocity = conveyor.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -conveyor.Configuration.Speed.Value))
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.