Hi there I need to make a Billboard gui that displays a “Shopping List” (List of Items a player needs to gather) and it needs to be randomized between 4 or 5 different list options. I also am trying to make it reset based on time length or list completion. But I can’t seem to figure out how it would work.
this is what I have so far
local served = false
local itemsGathered = script.Parent.itemsGathered
local currentTimer = 0
local timerOn
local function timer()
while served == false and currentTimer == 0 do
currentTimer = 90
timerOn = true
while timerOn == true do
wait(1)
currentTimer -= 1
print(currentTimer)
end
if currentTimer == 0 then
timerOn = false
end
end
end
local function resetTimer()
end
local function gatherItems()
local option1 = {"1 Bread", "2 Bananas", "1 Soda"}
local option2 = {"4 Bread", "1 Bananas", "2 Sodas", "1 Apple"}
local options = {option1, option2}
local chosenOption = options[math.random(1, #options)]
print(chosenOption)
end
while currentTimer == 0 do
timer()
gatherItems()
wait(currentTimer)
end
this script is kept in a text label on a billboardGui in workspace
sorry I know im not meant for the code to be written but I have been here for hours and nothing has worked
I’m a bit confused as to what you’re looking to achieve here. Are you looking to wait a certain amount of time until the timer times out or the player gathers all the items? Or make it restart if the player took a certain amount of time? Or something completely different?
Hi. Here’s how I’d modify your script to be clearer (IMO) and (maybe) work. There’s still some work to be done, like figuring out what items are currently gathered and checking if that equals the items that must be gathered. It’s mostly just to show the logical layout of having repeating rounds and how rounds can manage timers.
--... some stuff here. Not as many global variables though.
local ITEM_OPTIONS = {
{"1 Bread", "2 Bananas", "1 Soda"},
{"4 Bread", "1 Bananas", "2 Sodas", "1 Apple"},
}
function pickRandom(items)
local i = math.random(1, #items)
return items[i]
end
--Run an entire round.
function startRound()
--Initialize the round state variables
local gatheringComplete = false
local timeRemaining = 90
local itemsToGather = pickRandom(ITEM_OPTIONS)
--Wait for the round to be over (for any reason)
repeat
wait(1)
timeRemaining -= 1
gatheringComplete = areItemsGathered(itemsToGather) --TODO: Implement this
local roundOver = gatheringComplete or timeRemaining <= 0
until roundOver
--Done with the round
end
--Main loop. Just starts a new round every time the previous one ends, because startRound doesn't return until the round is over.
while true do
startRound()
end
Thank you so much for helping me out, I will try to implement this and see if it works. Thank you for the help. I know my code is super messy lol. I didn’t realise till yesterday you caould stack multiple variables in a singular table like that