Game stops and freezes

The game freezes and stops after 5 minutes. Absolutely everything stops and later after a minute or two it kicks and says that the connection is lost. Most likely i somehow screwed up in the scripts but I absolutely do not know because of what, I dont know if this will help, but in the dev console in network parameter default is the first. This is the case for all players in game and in other games all fine.

Local scripts work fine, but events and server scripts do not.
Please help, I have been suffering for two weeks

Check if any of your scripts have loops that dont wait, thats usually a common way of games crashing

while true do -- This script doesnt wait, it will run mulitple loops within a frame
print("E")
end

This Loop has a wait in it, runs every frame if you want it to:

while true do 
wait()
print("E")
end

Another Version of this is:

while wait() do 
print("E")
end

More info here: Introduction to Scripting | Roblox Creator Documentation

1 Like

I know about it, but yes this is probably the problem. I have a lot of cycles, loops and even a remote event that is sent almost every .3 seconds (and a few other players). I had a script on public servers that performed such a cycle:

--(example)

local ms=game:GetService('MessagingService')
local rs=game:GetService('ReplicatedStorage')
local serversFolder=rs.Servers

ms:SubscribeAsync('Servers',function(data)
   data=data.Data

   if data.id~=game.JobId then
        local sVal=script.template:Clone()
        sVal.Name='server'..#serversFolder:GetChildren()+1
        sVal.Value=data.id..','..dat.gm..','.data.map
        sVal.Parent=serversFolder

        wait(5)
        sVal:Destroy()
   end
end)

while game.VIPServerId==''do
   local data={
      id=game.JobId
      gm=rs.gm.Value,
      map=workspace.Map.Value
   }

  pcall(function() -- because too much requests
    ms:PublishAsync(data)
  end)
  
   wait(15)
end

I disabled this script and it was possible to play longer for 5 minutes :slight_smile: . Also, players complain about high ping. It is very likely that this is due to the high load on the Internet.

Try disabling every script and see if there are still crashes. If there is, enable them all back, and reinstall studio.

1 Like

Change this:

local ms=game:GetService('MessagingServer')

To this:

local ms = game:GetService("MessagingService")
1 Like

oh no, its just a mistake because I didnt copy the script from my computer. Errors have nothing to do with it, the main thing is the meaning

the saddest thing is that if I disable the scripts, half the game will stop working because they are very closely related, of course I can fix it, but its very very long

Yes but by disabling the scripts temporarily, you will be able to see if the scripts are the main cause of the crashing. Iā€™m not saying to keep them disabled forever.

1 Like

ok, I will try. Its just that when Iā€™m alone on the server or just a few people there are no such freezes

Update: it did not help

I also noticed such a thing, local scripts work fine, but events and server scripts do not :frowning:

A remote event firing every .3 seconds is probably the issue. Try to disable this and see if it still does this.

i removed this event and also optimized the events and reduced their amount. All the same :frowning:

by any chance do you have and moving parts in your game?

yes, but they are anchored and moving through tween (2 objects). There are 3 physical objects that can react to shots but they regenerate after a new round (max 3 min)

i solved.
the error was due to a script like

workspace.Folder.ChildAdded:Connect(function()
  if #workspace.Folder:GetChildren()>50 then
     workspace.Folder:ClearAllChildren()
  end
end)

im having a similar issue and cant figure out how to fix it, could you please tell me what was it exactly that was causing the issue?

1 Like

for me it was due to the fact that the script tried to set parent to object when the object was destroyed, and tried to do this about 300k times per second. It may also be due to game.Debris or something similar

i do use game.debris alot what do u mean it could be due to that?

The script in the post marked as the solution, was the issue. It is deleting objects the instant they are added into an object. Instances are not good with this type of behavior, thats why you can get this intimidating warning:

Something unexpectedly tried to set the parent of [?] to NULL while trying to set the parent of [?]. Current parent is [?]

So if you have a script that immediatly destroys or reparents instances that were just moved, this might be the cause of your issue. May you further explain your issue?

I dont get that but I just realized that the server memory is very high when there is multiple people in the game with 20 people it is already at 5000 and then once it hits 6000 it is when it crashes I dont know why it is so high