Laser not moving fast enough

I am trying to make a simple laser gun. However, my laser is not moving fast enough. I want it to move like Star Wars lasers – fast, but not so fast that you can’t see it, just a blur.

wait(3)
local part = script.Parent
while true do
	part.CFrame = part.CFrame + part.CFrame.lookVector
	
end

If I try this, it lags and I never see it move. If I add a wait at all, it still doesn’t move fast enough for my liking. How would I make it so my laser moves fast? I need to make sure it moves in the direction it’s facing too.

An example of what I want.

laser

Thanks for any help! :wink:

Yield the script with RunService:

game:GetService("RunService").Heartbeat:Wait()

This will yield once every frame according to the server’s performance.

task.wait(3)
local part = script.Parent
local speed = 2

while true do task.wait()
	part.CFrame += part.CFrame.lookVector * speed
end

change speed to how fast you want it to go

3 Likes
wait(3)
local part = script.Parent
while true do
	part.CFrame = part.CFrame + part.CFrame.lookVector
	game:GetService("RunService").Heartbeat:Wait()
end

It still is not going fast enough – sorry I’m picky. Anyway to make it faster?

Wait() has a minimum requirement of 0.03 seconds, run service does not.

Thanks, this works perfectly! I can now modify the speed and play around until I find a value that works. Thanks for your help as well @8_8io!

Then you will need to calculate the trajectory and tween the part with a fixed speed; use raycasting to find the end position and calculate waypoints along the trajectory.

task.wait() can run faster then that
I never used wait()

I actually didn’t know that there was a difference. I guess from now on I am using task.wait().

I recommend you look at the new task library
wait() is deprecated

1 Like