How to make timed power ups?

I have been looking for a way to make timed power ups like a running boost. I could do wait(seconds) but I would like to show the player how much time they have before it runs out. Should I use os.time(),tick(), or a different way? Also how would I use it and how would it work? Thank you in advance.

You can just tell the player how long their boost lasts. Then on the client just display the time left until it reaches BoostStart + BoostLength

local BoostStart = os.clock() 
local BoostLength = ... --// in seconds

local BoostEnd = BoostStart + BoostLength

for i = 1, BoostLength do
     print(BoostEnd - i)
     wait(1)
end
1 Like

Could you explain how this works??

Client-side prediction.

When a powerup is obtained, the server will enable anything for the powerup it needs to from its end and then tell the client that a powerup was obtained as well as how long it should last for. The client then applies visual effects and counts down a timer (might be good to use Heartbeat here). The server can just do a simple wait or use some kind of system that allows the passage of time. When that time is over, the server and client respectively turn off effects as needed.

So basically: you’re running systems independently here. When a powerup is obtained, the server first informs the client of what powerup was obtained as well as how long it should last for (or the client can determine the lasting time, doesn’t matter). They then run independently. Server simply enables, waits a bit then disables. Client does all the visual stuff. No need to synchronise time or get it completely accurate, since the client is predicting when the server will expire the powerup’s effects.

2 Likes

I was thinking if they can use a powerup folder in the server storage with all the abilities and the power up name, and the client specifies a string as the name of the powerup.
What do you think tho?

So I would have to make the client predict when it started and when it ended. Thank you for the help!