game.ReplicatedStorage.ScreenShake.OnServerEvent:connect(function(player, duration) local humanoid = player.Character.Humanoid local timer = tick() if humanoid.Health <= 1 then return end while timer <= duration do print("d") humanoid.CameraOffset = Vector3.new(math.random(-2, 2), math.random(-2, 2), math.random(-2, 2)) wait(0.2) end humanoid.CameraOffset = Vector3.new(0, 0, 0) end)
Problem is when I print (timer, duration) it will print the timer as like a number in the 1,000,000s and the duration as 2. How do I make it so that timer is the time that has passed since I started the loop so that when it passes the duration the camera will stop shaking?
P.S. using this so I can just fire it to the server whenever I need it shake.
You probably don't want to use tick()
here.
timer = 0 -- ... while timer <= duration do -- ... timer = timer + wait(0.2) end
You see, wait()
actually already returns the amount of seconds that it waited, so you can use that to your advantage.
In other news, the comments are right. This should really be done on the client.