Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago
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.

0
ScreenShake is an effect so should be done on the client side User#5423 17 — 5y
0
^ Yup, he's right! Only the locals can feel it. magicguy78942 238 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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.

Ad

Answer this question