My Game just Freezes When Making a New Server

Hello! I had been getting complaints that my game has just been freezing before the load screen even closes. (I’m talking about the ROBLOX loadscreen shown at the start of any roblox game)… So, I join, and all the complaints are right. ;-;

I need help making this go away, my game never had this much lag, and either there’s lag, or a problem…?

The only changes I made were to add a few new “while true do” scripts… this shouldn’t make such major lag, they were simple scripts.

Anybody have a solution that I can use, or even know what the problem is? It’s only my game…

Anybody know a script to combat this?

EDIT: I find this an issue with WHILE TRUE DO scripts in almost all of my games… Whenever I do one, even a simple one, the lag increases TREMENDOUSLY.
Example of simple script:

while true do

if game.Workspace.Enabled.Value == true then

script.Parent.Visible = true

end
1 Like

You’ll need to put some kind of yield in your loops. Some of the most common ways to do this are either to use RunService.Stepped or replace while true do with while wait() do.

Without a yield, the game is essentially trying to execute an infinite number of processes, all at once.

From what you’re doing here, you can probably listen to Changed on the value object Enabled.

workspace.Enabled.Changed:Connect(function(value)
    if value then
        script.Parent.Visible = true
    end
end)
if workspace.Enabled.Value then
    script.Parent.Visible = true
end

Don’t really recommend. A wait in the while condition is misuse of its condition. Add the wait at the bottom of a while iteration. Use a truthy value for non-terminating loops.

2 Likes