Is it possible to cap FPS?

But they don’t?

Are you sure trying to patch the >60 FPS advantage is absolutely not possible? I feel like that’d be a better solution than trying to use use an FPS cap as a bandaid.

1 Like

They do.

6 Likes

Interesting; didn’t notice that was a thing. Curious as to how the man does it now.

Maybe you could try writing some kind of function that waits enough time for FPS to be <= 30 using RunService.RenderStepped?

Although I still would rather look into why the >60 FPS advantage can’t be fixed.

1 Like

The advantage is the speed you can ascend in terrain water.

Probably has something to do with RenderStepped, really hoping roblox can change the water terrain swimming mechanics in the future though.

Couldn’t figure out a good solution so instead moved to tackling the FPS as a short-term solution.

2 Likes

Yes it is possible to do FPS capping, using tick() and RenderStepped. I made a 60FPS cap script, but keep in mind scripts like these can cause unnecessary lag. I personally use fps unlockers, so I just changed all my RenderStepped functions to be independent of frame rate by using DeltaTime so that I wouldnt need the FPS script anymore

4 Likes

Try this:

local fps = 30
local clock = tick()

while true do
    while clock + 1/fps > tick() do end
    wait()
    clock = tick()
end

Credit to @1waffle1 for the script.

25 Likes

where did the “fps” come from?

Is this from a renderstepped script or something

1 Like

Just declare fps in the beginning of the script.
Edit: I have modified the script.

1 Like

Aight I understand, cool

30 charrr

1 Like

I made a script, copy pasted your script, and placed it in ServerScriptStorage.

Hey, just tested it out. It works for me in Studio but not in game, I’m still clueless why.

1 Like

ServerStorage is for storing items not needed to be replicated to clients

2 Likes

In a studio test the client and server ends are running on the same machine (yours). In an online game that script would only be slowing down the server. It needs to slow down the client. So @OptimisticSide’s code should be put in a local script in StarterPlayerScripts.

2 Likes

Did as you said and I tested it out.

The script lowered the FPS count but did not really cap it to the number listed.

Ex. I set the fps variable to 10, when I went into my place with my FPS unlocker my FPS was still around 130 FPS
When I had the variable set to 60 I was around 180 FPS
When I had the script disabled I was around 270 FPS

1 Like

You aren’t supposed to cap the FPS if it gives you an advantage. You’re supposed to write code that works with all framerates.

local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function(deltaTime)
    -- multiply the movement amount by deltaTime.
end)

You most likely forgot to multiply the movement by deltaTime before you applied it on the player. Delta time is basically the time it took to render the last frame, and it’s useful in creating smooth animations on any framerate, and making sure things tied to renderstep happen at the same speed on all clients, no matter what their framerate is.

In the unlikely even that it’s in a roblox script, you can just clone the roblox scripts while you’re testing and then paste it into studio when you’re done testing. Then, find the code that relates to swimming and make sure they are multiplying the movement by deltaTime. If they aren’t, you can edit the script to fix it, and then file a bug report.

Capping FPS is going to make a lot of players confused/annoyed, and they’re probably going to leave the game because of it. Instead of finding a hacky solution like capping FPS, you should just fix the actual issue.

There’s a helpful devforum article on it here:

13 Likes

I know this conversation happened a few months ago, but I was trying to do the same thing and the script didn’t work. It capped fps, but not at the specified number. I don’t know why this is. Ex: Specified number: 10 Fps: 22

1 Like

This is a better script:

local RunService = game:GetService("RunService")
local MaxFPS = 30
while true do
    local t0 = tick()
    RunService.Heartbeat:Wait()
    repeat until (t0 + 1/MaxFPS) < tick()
end

Note this won’t be exact (normally within 5 fps, lower fps values will be closer to the desired FPS) but is closer than what was posted. Also, unless this is for an effect (like Super Nostalgia Zone’s 30 fps cap to emulate old roblox), code should be designed to work on any framerate, so just keep that in mind :slightly_smiling_face:

19 Likes

Thanks for the help. I just tested it and it capped at exactly 30.

1 Like

its not but i think you can kick players manually by counting the fps

local RS = game:GetService("RunService")
local FPS = 0
local player = game.Players.LocalPlayer
RS.RenderStepped:Connect(function()
FPS += 1
end)
while task.wait(1) do
if FPS > 63 then
player:Kick()
else
FPS = 0
end
end

you need to make the fps count a little bit more higher than 60 because sometimes roblox exceeds that limit
(just realized im super late😅 sorry for that)

2 Likes

I know it may be unimportant, but reorganizing your code with the proper tabs/spaces will help newer people understand what it’s doing a lot faster

1 Like

You can probably fix the speed issue by dividing it by the time passed using os.clock()