Increase the speed using vector3

I am making a block sliding across the screen. I am trying to make it move at a faster speed but no matter how many 0s I add to the wait it does not increase. This is probably because I have reached the minimum value.How do I make the block move faster?
(I do not have much experience using vector 3. The x position is at 0.125 studs so the block moves as smoothly as possible. I am using this as a template to understand how Roblox vehicles move using scripts.) This is my code:


local part = script.Parent
while true do
	part.Position = part.Position + Vector3.new(0.125, 0, 0)	
	wait(0.00000125)
	print("Running")
end

maybe you should use task.wait() instead

The wait() function has an automatic minimum of 0.03. So making it smaller wouldn’t change anything.

I recommend using RunService, specifically RenderStepped. Make sure it’s on the client. This is likely your fastest method.

local RS = game:GetService("RunService")
RS.RenderStepped:Connect(function(dt)
    part.Position = part.Position + Vector3.new(.125 * dt, 0, 0) -- dt is deltaTime 
end)

task.wait() is the same thing as RS.RenderStepped:Wait() yk

or hearbeat

Instead of using RenderStepped which required the client, he should use RunService.Heartbeat which can be used on the server.

You could Increase the Value that It goes up by to increase the speed too!

A block sliding across the screen sounds like it’s more important to the client rather than to the server which is why I recommended a client-sided method. Putting stuff like this on the client is generally better as it helps to prevent lag.

Regardless, task.wait and heartbeat are equally viable if OP wants the block to move faster.

BodyVelocity could also be used as for they are smoother than constantly updating position.

2 Likes

Maybe this sounds silly, but if I put it on the client will only be shown to that person and not everyone else in the server or will it just run on the client but everyone will see it?

1 Like

That’s not silly at all, it’s actually a valid concern; it will only show up for that particular client. To solve this, we have each client run the same script on their own end.

A very easy way to do this is to have a LocalScript in the client that handles the block-moving and a RemoteEvent in ReplicatedStorage where every time it is triggered, the LocalScript moves the block. Then just have the server do FireAllClients() on the RemoteEvent to have every client render the block moving. You could also pass through some parameters to the RemoteEvent if you want the block to be positioned somewhere specific.

2 Likes