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

This script freezes my game and I don't know why. Please help?

The script (posted below) will freeze the server and I don't see why. This code is part of my Build Battle game, so after it is resolved I will censor it, but only because I don't want people stealing my game.

function doSpecialRound(buildTime, voteTime, intermissionTime)
	throw("notification","This round will be different!")
	wait(11)
	throw("notification","This round you will have to guess what the player is building")	
	setStatus("Choosing builder...")
	wait(3)
	player = get_Child(game.Players,math.random(0,#game.Players:GetChildren()))
	if player.Character and player.Character.HumanoidRootPart then
		player.Character:MoveTo(workspace.Teleports.LobbyBase.base.Position)
	end
	-- Give tools
	for i,v in pairs(game.ServerStorage.StamperTools:GetChildren()) do
		tool = v:Clone()
		tool.Parent = player.Backpack
	end
	ncs = script.Resources.NoChatScript:Clone()
	ncs.Parent = player.Backpack
	ncs.Disabled = false
	workspace.MakeChat:FireAllClients("The bonus round has started! Chat what you think the builder is making!")
	i = 90
	category = tostring(cat[ch])
	for i,v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.main.Frame.Category.Text = "Mystery"
	end
	player.PlayerGui.main.Frame.Category.Text = category
	-- Chat hook
	setStatus("Mystery round...")
	for i,v in pairs(game.Players:GetChildren()) do
		pcall(function()
		v.Chatted:connect(function(msg)
			if string.lower(msg) == string.lower(category) then
				throw("msg",v.Name .. " has guessed the theme!")
				workspace.MakeChat("The theme was " .. category)
				game.PointsService:AwardPoints(v.UserId,100)
				v.leaderstats.Wins.Value = v.leaderstats.Wins.Value+1
				for i,v in pairs(game.Players:GetChildren()) do
				pcall(function()
				v.Chatted:disconnect() -- Deprecated, but options are limited
				end)
				end
			end
		end)
		end)
	end
	while i > -1 do
		for i,v in pairs(game.Players:GetChildren()) do
			pcall(function()
			v.PlayerGui.main.Frame.Time = i
			i=i-1
			wait(1)
			end)
		end
	end
end

EDIT (1):

local get_Child=function(obj,index)
	return obj:children()[tonumber(index)]
end

2 comments

0

Beyond me, I would help... if I could

0

Ok thanks for the quick reply though

2 answers

Pretty sure its got to do with the while loop on line 45, no idea what you are trying to do in this loop but its wrong.

For instance, you use i as your timer number but also reuse it in a for loop on line 47 (for i,v) so the timer version of i never gets subtracted from because you only subtract within this loop. Rename one of the i's.

Also line 38, :disconnect is deprecated but :Disconnect() isn't so if you wanna change that.

3 comments

0

ah, i thought Disconnect() and disconnec() were the same, thanks for the clarification. And also thanks for the help!

0

Did the help fix your issue or are you still having trouble?

0

no, sorry. the freeze still occurs

Alright, so the problem still occurs, and here is the revised code:

function doSpecialRound(buildTime, voteTime, intermissionTime)
	throw("notification","This round will be different!")
	wait(11)
	throw("notification","This round you will have to guess what the player is building")	
	setStatus("Choosing builder...")
	wait(3)
	player = get_Child(game.Players,math.random(0,#game.Players:GetChildren()))
	if player.Character and player.Character.HumanoidRootPart then
		player.Character:MoveTo(workspace.Teleports.LobbyBase.base.Position)
	end
	-- Give tools
	for i,v in pairs(game.ServerStorage.StamperTools:GetChildren()) do
		tool = v:Clone()
		tool.Parent = player.Backpack
	end
	ncs = script.Resources.NoChatScript:Clone()
	ncs.Parent = player.Backpack
	ncs.Disabled = false
	workspace.MakeChat:FireAllClients("The bonus round has started! Chat what you think the builder is making!")
	timer = 90
	category = tostring(cat[ch])
	for i,v in pairs(game.Players:GetChildren()) do
		v.PlayerGui.main.Frame.Category.Text = "Mystery"
	end
	player.PlayerGui.main.Frame.Category.Text = category
	-- Chat hook
	setStatus("Mystery round...")
	for i,v in pairs(game.Players:GetChildren()) do
		pcall(function()
		v.Chatted:connect(function(msg)
			if string.lower(msg) == string.lower(category) then
				throw("msg",v.Name .. " has guessed the theme!")
				workspace.MakeChat("The theme was " .. category)
				game.PointsService:AwardPoints(v.UserId,100)
				v.leaderstats.Wins.Value = v.leaderstats.Wins.Value+1
				for i,v in pairs(game.Players:GetChildren()) do
				pcall(function()
				v.Chatted:disconnect() -- Deprecated, but options are limited
				end)
				end
			end
		end)
		end)
	end
	while timer > -1 do
		for _,v in pairs(game.Players:GetChildren()) do
			pcall(function()
			v.PlayerGui.main.Frame.Time = timer
			timer=timer-1
			wait(1)
			end)
		end
	end
end

4 comments

0

Is it possible your pcall is failing at line 48 causing line 49 and 50 to not run, so it is a endless loop with no waits? Put the wait and timer subtraction outside the pcall and see what happens.

0

ok, smart idea

0

Edit the question + comment on previous answer rather than posting another answer plz :)

0

Ok the problem is solved! Thanks for all your help. You can see the script in-action on my Build Battle game. (1158750748)

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