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

Why does this anti repeat not work?

I have 3 pads in the Workspace. I made this function to pick 3 random maps and display them on the boards.

The problem is that I don't want the same map to show up on any of the other boards as one board. I've tried a series of solutions, but none have worked.

Does anyone have a simple solution?

function PickRandomCubes()
Picked = {}
for Index,Board in pairs(Workspace.Vote:GetChildren()) do
print(Board.Name)
Maps = game.ServerStorage.CubeMapI:GetChildren()
Map = Maps[math.random(1,#Maps)]
for Index,A in pairs(Picked) do
if Map.Name == A.Name then
repeat Map = Maps[math.random(1,#Maps)] until Map.Name ~= A.Name
end
end
table.insert(Picked,Map)
Board.SurfaceGui.ImageLabel.Image = Map.Value
Board.SurfaceGui.MapName.Text = Map.Name
end
end

1 answer

function PickRandomCubes()
	local t={}
	local maps=game.ServerStorage.CubeMapI:GetChildren()
	for i,board in pairs(workspace.Vote:GetChildren())do
		local index=math.random(1,#maps)
		t[#t+1]=maps[index]
		maps[index]=nil
		local unpicked={}
		for _,v in next,maps do
			unpicked[#unpicked+1]=v
		end
		maps=unpicked
		board.SurfaceGui.ImageLabel.Image = Map.Value
		board.SurfaceGui.MapName.Text = Map.Name
	end
end

Each map is added to a list of maps to choose from. Each time a map is chosen, it is removed from the list.

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