So I'm trying to make three different gui's display three different pictures randomly. I have it set up so that based on two different random number variables it will pick which panel it will display which picture on. I want to make it so that once it chooses one panel it won't pick that panel anymore and can only select from the two non-selected panels left, and once it picks a certain picture it wont pick that picture any more. However, it works for two of the panels and just infinitely loops. What is wrong with my code?

local fall1 = game.Workspace.storage.eventImages.fall1--platform fall by 1 increment
local fall5 = game.Workspace.storage.eventImages.fall5--platform fall by 5 increments
local rise5 = game.Workspace.storage.eventImages.rise5--platform rise by 5 increments

local panel1 = script.Parent.Parent.eventPanels.eventPanel1
local panel2 = script.Parent.Parent.eventPanels.eventPanel2
local panel3 = script.Parent.Parent.eventPanels.eventPanel3

local panel1Selected = false
local panel2Selected = false
local panel3Selected = false

local event1Selected = false
local event2Selected = false
local event3Selected = false

local eventStartCount = 1
local eventAmount = 3--amount of events
local eventName = ""

local loopCount = 1

while eventStartCount <= 3 do

	local randEvent = math.random(1, eventAmount)--random number to pick event
	local randPanel = math.random(1, 3)--random number to pick which panel to display event
	
	if randEvent == 1 then
		eventName = "fall1"
	elseif randEvent == 2 then
		eventName = "fall5"
	elseif randEvent == 3 then
		eventName = "rise5"
	end
	
	print("Random Event ", loopCount, ": ", eventName)
	print("Random Panel ", loopCount, ": ", randPanel)
	
	if randPanel == 1 and panel1Selected == false then--if the random panel number happens to be 1 and if the panel1 isnt being used
		if randEvent == 1 and event1Selected == false then
			panel1.SurfaceGui.ImageLabel.Image = fall1.Texture
			event1Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 2 and event2Selected == false then
			panel1.SurfaceGui.ImageLabel.Image = fall5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 3 and event3Selected == false then
			panel1.SurfaceGui.ImageLabel.Image = rise5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		end
		panel1Selected = true --tell the script panel1 was selected
	end
	
	if randPanel == 2 and panel2Selected == false then--if the random panel number happens to be 2 and if the panel2 isnt being used
		if randEvent == 1 and event1Selected == false then
			panel2.SurfaceGui.ImageLabel.Image = fall1.Texture
			event1Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 2 and event2Selected == false then
			panel2.SurfaceGui.ImageLabel.Image = fall5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 3 and event3Selected == false then
			panel2.SurfaceGui.ImageLabel.Image = rise5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		end
		panel2Selected = true --tell the script panel2 was selected
	end
		
	if randPanel == 3 and panel3Selected == false then--if the random panel number happens to be 3 and if the panel3 isnt being used
		if randEvent == 1 and event1Selected == false then
			panel3.SurfaceGui.ImageLabel.Image = fall1.Texture
			event1Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 2 and event2Selected == false then
			panel3.SurfaceGui.ImageLabel.Image = fall5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		elseif randEvent == 3 and event3Selected == false then
			panel3.SurfaceGui.ImageLabel.Image = rise5.Texture
			event2Selected = true
			eventStartCount = eventStartCount + 1
		end
		panel3Selected = true --tell the script panel3 was selected
	end
	
	loopCount = loopCount + 1
	wait()
end

4 comments

0

Try putting your panels in a table and use table.remove(math.random(etc..)) to remove them. That way you can automatically see which panels have not been selected becasue only those that haev not been selected will still be inside your table.

0

Thank you

0

Mark this as answered, this is my second time today I tried to help someone to find that their problem is already solved. XD

0

yup. or someone could downvote to get it outa here