Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my script freeze at this point?

Hello, I have been working on a minigame script, and the game seems to work perfectly, but when enough people are playing it freezes at this part on the script randomly.

To summarize: The script can work with 20 people, but after awhile it randomly breaks displaying one of those texts as hints.

I'm not sure if it freezes because a player leaves the game or what. Can someone help me put a check in the script to prevent it from breaking? Any help would be really appreciated!

while cc < 2 do
		cc = 0
		c = game.Players:GetChildren()
		for num, obj in pairs(c) do
			if obj:FindFirstChild("Playing") then
				if obj.Playing.Value then
					cc = cc + 1
				end
			end
		end
		h.Text = "Need at least 2 players to begin games"
		wait(1)
	end
	h.Text = "New round will begin soon..."
	wait(3)
	h.Text = "Choosing random game..."
	wait(3)
	m = game.Lighting.Minigames:GetChildren()
	mg = m[math.random(1,#m)]
	map = mg.Map
	set_spawns(map)
	map.Parent = game.Workspace
	h.Text = (""..mg.Name)
	wait(5)
	h.Text = "Get ready to fight..."
	wait(2)
	c = game.Players:GetChildren()

1 answer

So I'm going to assume this is the whole script. You are ending the while loop early, so once the script ends, it stops because it's not inside a loop. The script will run regardless of player count.

while true do --Note this loop has an "end" all the way at the end of the script. The script will keep repeating itself now.
	while cc < 2 do
	        cc = 0
	        c = game.Players:GetChildren()
	        for num, obj in pairs(c) do
	            if obj:FindFirstChild("Playing") then
	                if obj.Playing.Value then
	                    cc = cc + 1
	                end
	            end
	        end
	        h.Text = "Need at least 2 players to begin games"
	        wait(1)
	    end
	    h.Text = "New round will begin soon..."
	    wait(3)
	    h.Text = "Choosing random game..."
	    wait(3)
	    m = game.Lighting.Minigames:GetChildren()
	    mg = m[math.random(1,#m)]
	    map = mg.Map
	    set_spawns(map)
	    map.Parent = game.Workspace
	    h.Text = (""..mg.Name)
	    wait(5)
	    h.Text = "Get ready to fight..."
	    wait(2)
	    c = game.Players:GetChildren()
end

1 comment

0

It is not the whole script, just the part the script freezes on sometimes.

This discussion is preserved as it was. New answers, comments, and votes are closed.