Hold for Power Problem

Hi all,

My issue is related to my football game. I noticed that when a player lags, the power bar fills slowly whereas if a player uses an FPS unlocker, the power bar fills almost instantly.

This is the simple code I use for when the player holds their mouse down:

for i=1,40 do
	power += 1.25
	highPower += 1.25

This should be the expected behavior:

However, when I’m on my phone (low FPS), it takes so much longer for the power bar to fill up.

This is the example of my friend using an FPS unlocker in my hockey game. (both games use the same code for shooting) It fills up instantly:

Is there a way to make the speed of the power bar independent of the client’s FPS? This issue makes it harder for players with low FPS to play the game fairly. Is there an alternative to task.wait() that could solve this problem?

Thanks in advance!

1 Like

This is why, task.wait without an argument tells the engine to wait for exactly 1 frame. So if a user has 30 fps per second the engine will wait for 1/30 = 0.033 seconds. But if a user uses an fps unlocker and has lets say 120 fps, then the engine will wait for 1/120 = 0.008 seconds, which is 4 times less than the 30 fps user.

I assume a possible fix is to use a constant wait value for task.wait:

local t = 1/30
task.wait(t) --this will wait for 0.333 seconds for high fps users as well
1 Like

Sorry to correct you (and you probably didn’t verify what you wrote) but this is not 0.333, this is 0.033


That was an interesting read, but I’m not sure how I can apply that in my situation. It appears that DeltaTime is ideal for timers. I’ve tried to implement it in my shooting system but I just ended up confused.

1 Like

I tried your suggestion but the FPS still affects the shooting power speed, just not as bad as before.

Why not using a NumberValue with tick() as value when the player press and check tick() - NumberValue.Value when he release the button?

How would that make any difference? It’s just going to make things harder for no reason

Alright, it seems your problem is only locally for the bar. I suggest then:
Tween the bar for the final size and for the maximum amount of time it should be. When the player release key, just do tween:Stop()

I was able to solve my issue with DeltaTime. Thanks for the solution.

1 Like