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
task.wait()
end
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?
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
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.
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()