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

No Output problem, yet it still wont work!?

Well this is the script, it didn't work when I tried it out, someone said, I needed to remove the "End"'s to the functions, I did but it just spammed the messages, not the maps I even checked. Help please, this is for someone else, and they need it.. Could someone help me out!?

Maps = {"Wobbly Bridge","Tower Of Magic"}
Time_Per_Round = 60
HowLongMessageLasts = 5
HowLongVotingPeriodLasts = 15
MessageToBeStated = "Seconds Left: "
Option = 1
COLOR = 1 
function Op1()
	m = Instance.new("Message", Workspace)
	m.Text = "Map Selected: ".. MAP .."!"
	wait(3)
	m:Destroy()
end
function Op2()
	m = Instance.new("Message", Workspace)
	m.Text = "".. MAP .."____ was picked!"
	wait(3)
	m:Destroy()
end
function Op3()
	m = Instance.new("Message", Workspace)
	m.Text = "You will be playing on the ".. MAP .." map"
	wait(3)
	m:Destroy()
end
function Op4()
	m = Instance.new("Message", Workspace)
	m.Text = "Map/"
	wait(3)
	m:Destroy()
end
Players = game.Players:GetPlayers()
Ls = game.Lighting:GetChildren()
_G.MAPA = {"Wobbly Bridge"}
_G.MAPB = {"Tower Of Magic"}
_G.MAPE = {}
_G.MAPF = {}
_G.MAPG = {}
_G.MAPH = {}
_G.MAPI = {}  
_G.MAPJ = {} 
_G.MAPK = {}  
_G.MAPL = {}  
_G.MAPM = {} 
_G.MAPN = {} 
_G.MAPO = {} 
_G.MAPP = {} 
_G.MAPQ = {} 
_G.MAPR = {}  
_G.NothingCurrently = {}
Lasting = HowLongVotingPeriodLasts
while true do
	HowLongVotingPeriodLasts = Lasting
	if #Players > 1 then
		for o = 1,#Players do
			gui = game.Lighting.Vote:Clone()
			gui.Parent = Players[o].PlayerGui
		end
		repeat
			a = HowLongVotingPeriodLasts
			wait(1)
			m = Instance.new("Message", Workspace)
			m.Text = "Voting Time: "
			a = a - 1
			wait(1)			
		until a == 0
		m:Destroy()
		for i = 1,#Players do
			val = Players[i].Map.Value
			table.insert(_G[val], val)
		end
			mapn = math.max(#_G.MAPA, #_G.MAPB, #_G.MAPC, #_G.MAPD, #_G.MAPE, #_G.MAPF, #_G.MAPG, #_G.MAPH, #_G.MAPI, #_G.MAPJ, #_G.MAPK, #_G.MAPL, #_G.MAPM, #_G.MAPN, #_G.MAPO, #_G.MAPP, #_G.MAPQ, #_G.MAPR)
			if #_G.MAPA == mapn then
				for u = 1,#Ls do
					if Ls[u]:FindFirstChild("A") ~= nil then
						Pick = Ls[u]
					end
				end
			end
		Mapp = Pick:Clone()
		Mapp.Parent = Workspace
		MAP = Mapp.Name
		if Option == 1 then
			Op1()
		elseif Option == 2 then
			Op2()
		elseif Option == 3 then
			Op3()
		elseif Option == 4 then
			Op4()
		else
			print("Invalid option")
		end
		for y = 1,#Players do
			if COLOR == 1 then
				Players[y].TeamColor = BrickColor.new("Really red")
				COLOR = 2
			elseif COLOR == 2 then
				Players[y].TeamColor = BrickColor.new("Really blue")
				COLOR = 1
			end
		end
	end
end

1 answer

Unless this script is disabled and enabled by another script, it is running as soon as the server starts. On line 32 you get the players. At the time this code runs, there will be zero players in the game. At various points within your infinite loop, you check the number of players and always get zero because Players is never updated. The check on line 54 will always be false.

Additionally, when there are no players or when there is only one player, the infinite loop beginning on line 52 becomes a tight loop, iterating many times very rapidly, using unnecessary resources.

To address these issues, move line 32 inside the loop. Put it as the first line inside the loop. Also, add a wait(10) inside your loop if there are fewer than 2 players:

while true do
    Players = game.Players:GetPlayers()
    HowLongVotingPeriodLasts = Lasting
    if #Players > 1 then
		--existing code here
    else
        wait(10)
    end
end

There are still a number of bugs in your code, but this should get you to the point where you can see the code functioning and what you need to change. (For instance, you are never destroying the messages that you create on line 62.)

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