Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Am I using tick() incorrectly? How do I reset it for my function?

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.

2 comments

0

ScreenShake is an effect so should be done on the client side

0

^ Yup, he's right! Only the locals can feel it.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.