Often people ask how to prevent lag or minimize it, but for my project I want to create lag in a controlled way. I want this to be an event for a mysterious game called “The Void” where the game lags out (for the client) and then stuff visually changes after the lag subsides. How could I do this without crashing the client?
I’m not exactly sure what type of lag you’re looking for, but you can create an artificial FPS cap with something like this:
local runService = game:GetService('RunService')
local maxFPS = 1
while true do
local t = tick()
runService.RenderStepped:Wait()
repeat until (t + 1/maxFPS) <= tick()
end
I wouldn’t go lower than 1 though.
Source:
Alternatively, you could simply freeze the game until a certain time:
function freeze(time:number)
local t = os.time() + time
repeat until os.time() >= t
end
freeze(5)
game.RunService.RenderStepped:Connect(function()
for i=1,10 do -- change 10 to your lag intensity
task.spawn(function() math.sqrt(i*100) end)
end
end)
This would cause a lot of lag. To disable it you could just connect it to a connection and then just disconnect it when you would like do. e.g. connection:Disconnect() or connection = nil.
I’m pretty sure both of these would work.
This is a very strong lag so watch out and dont set the number more than 4 because you do not want to lag very much.