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.
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
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
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)
I don’t want to be kicked just because I used an FPS unlocker, and maybe Roblox will use VSync in future instead of a 60 FPS cap, making this code kick everyone who has a monitor with a higher refresh rate.
local RunService = game:GetService("RunService")
local MaxFPS = 30
while true do
local t0 = tick()
RunService.RenderSteppedt:Wait()
repeat until (t0 + 1/MaxFPS) < tick()
end
i didnt make it but it works just fine.
edit : just realized this was posted here before.
Returns how much time has elapsed, in seconds, since the UNIX epoch, on the current local session’s computer. The UNIX epoch is represented by the date January 1st, 1970.
for anyone looking for a better solution, this caps it at exactly the cap you put, even if they are using an fps unlocker or anything else it will still work
local fpsCap = 165
local clock = tick()
game:GetService("RunService").RenderStepped:Connect(function()
while clock + 1 / fpsCap > tick() do end
clock = tick()
task.wait()
end)
local RunService = game:GetService("RunService")
local fps = 22
local FT = 1 / fps
RunService.RenderStepped:Connect(function()
local sTime = tick()
while tick() - sTime < FT do
-- dont have to do anything here but u can if u want
end
end)
Ran accross this a while back. Never had a need to really test it for a game.
You need to let it run for a bit and it seems to lower the FPS as stated in FPSCAP.
local FPSCAP = 30 --cap
local LOOPCount = 40 --finetune
local MLoopCount = 27 --finetune
local FPS = 0
local Broken = 0
local function DOLOOP()
spawn(function()
while true do
game:GetService("RunService").Heartbeat:Wait()
if FPS+5 < FPSCAP and Broken <= LOOPCount*MLoopCount then
Broken += 1
break
end
end
end)
end
game:GetService("RunService").RenderStepped:Connect(function(delta)
FPS = 1/delta
end)
spawn(function()
while true do
game:GetService("RunService").Heartbeat:Wait()
if FPS >= FPSCAP then
spawn(function()
for i = 1, LOOPCount do
DOLOOP()
end
end)
end
end
end)
spawn(function()
while wait(1) do
Broken = 0
end
end)
You’ll have to test it yourself, it may not be the best way to go about this.
getting the fps is more simpler than that code because RunService.RenderStepped returns the deltatime which is the time between the last frame and the present frame.
we can get the fps by getting the reciprocal of the deltatime.
local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function(deltaTime)
local fps = 1//deltaTime
print(fps)
end)