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

imagelabel wont stop adding?

i want to make a vote system with image on it.but when i run a code it runs like 1000+ times like this https://gyazo.com/84a6b2b998aee21b738ef60b6429e2b1 i dont know how to fix it, any help would be appreciated

heres the script

local start = tick()
while wait() do
	if tick()-start >= settings.mapVoteTime then break end 
	local secondsleft = math.floor(settings.mapVoteTime-(tick()-start))
	stats.Status.Value = secondsleft.." "..((secondsleft==1 and "second" or secondsleft==0 and "second")or "seconds").." to choose lmao"
	for e,f in pairs(Game.Special.Board:GetChildren()) do
		for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
			local playerVoting, mName 
			for d,c in pairs(mapVotes) do
				if c.id == tonumber(f.Name:match("%d+")) then
					playersVoting = #c.players
					mName = c.mapName
					if mName == "Basement" then
						local imagelabel = Instance.new("ImageLabel",f.sGui)
						imagelabel.Position = UDim2.new(0,0,0.1,0)
						imagelabel.Size = UDim2.new(1,0,0.9,0)
						imagelabel.Image = "rbxassetid://73737626"
						imagelabel.Name = "Epic"
						print("imagelabel has been added")
					elseif mName == "Mall" then
						local imagelabel = Instance.new("ImageLabel",f.sGui)
						imagelabel.Position = UDim2.new(0,0,0.1,0)
						imagelabel.Size = UDim2.new(1,0,0.9,0)
						imagelabel.Image = "rbxassetid://112902314"
						imagelabel.Name = "Epic"
					elseif mName == "Office" then
						local imagelabel = Instance.new("ImageLabel",f.sGui)
						imagelabel.Position = UDim2.new(0,0,0.1,0)
						imagelabel.Size = UDim2.new(1,0,0.9,0)
						imagelabel.Image = "rbxassetid://435858274"
						imagelabel.Name = "Epic"
					elseif mName == "ChapterTwo" then
						local imagelabel = Instance.new("ImageLabel",f.sGui)
						imagelabel.Position = UDim2.new(0,0,0.1,0)
						imagelabel.Size = UDim2.new(1,0,0.9,0)
						imagelabel.Image = "rbxassetid://149369874"
						imagelabel.Name = "Epic"
					end
					break
				end
			 end		
		end
	end
end

1 answer

✓ Accepted answer
  1. You made three for loops and did not end them until the end of the script. That means everything after the loops is going to be executed within the loops, so maybe that is why there are more imageLabels than you wanted.

  2. If you fixed the first problem that I addressed and it still doesn't work, then I think it may also be because you added your break too early on line 39. You ended your last "if" statement and then did a break without ending the other if statements and for loops. I think that is why it keeps running the code over and over again. Try placing your break later. I just edited the Script so look on the line where I believe it is causing the trouble:

local start = tick()
while wait() do
    if tick()-start >= settings.mapVoteTime then break end 
    local secondsleft = math.floor(settings.mapVoteTime-(tick()-start))
    stats.Status.Value = secondsleft.." "..((secondsleft==1 and "second" or secondsleft==0 and "second")or "seconds").." to choose lmao"
    for e,f in pairs(Game.Special.Board:GetChildren()) do
        for a,b in pairs(Game.Special.VotingPads:GetChildren()) do
            local playerVoting, mName 
            for d,c in pairs(mapVotes) do
                if c.id == tonumber(f.Name:match("%d+")) then
                    playersVoting = #c.players
                    mName = c.mapName
                    if mName == "Basement" then
                        local imagelabel = Instance.new("ImageLabel",f.sGui)
                        imagelabel.Position = UDim2.new(0,0,0.1,0)
                        imagelabel.Size = UDim2.new(1,0,0.9,0)
                        imagelabel.Image = "rbxassetid://73737626"
                        imagelabel.Name = "Epic"
                        print("imagelabel has been added")
                    elseif mName == "Mall" then
                        local imagelabel = Instance.new("ImageLabel",f.sGui)
                        imagelabel.Position = UDim2.new(0,0,0.1,0)
                        imagelabel.Size = UDim2.new(1,0,0.9,0)
                        imagelabel.Image = "rbxassetid://112902314"
                        imagelabel.Name = "Epic"
                    elseif mName == "Office" then
                        local imagelabel = Instance.new("ImageLabel",f.sGui)
                        imagelabel.Position = UDim2.new(0,0,0.1,0)
                        imagelabel.Size = UDim2.new(1,0,0.9,0)
                        imagelabel.Image = "rbxassetid://435858274"
                        imagelabel.Name = "Epic"
                    elseif mName == "ChapterTwo" then
                        local imagelabel = Instance.new("ImageLabel",f.sGui)
                        imagelabel.Position = UDim2.new(0,0,0.1,0)
                        imagelabel.Size = UDim2.new(1,0,0.9,0)
                        imagelabel.Image = "rbxassetid://149369874"
                        imagelabel.Name = "Epic"
                    end 
                    end
                end
             end        
        end
    break
end

1 comment

0

Oh wow it works thanks dude

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