How to repeat math.Random

so the scenario I have right here is that
I have a code that picks a random fruits with a while loop but i was wondering if there is a way that i can repeat math.random so i wont get a duplicate

> local coolown = 3
> 
> local Fruits = {"Apples","Orange","Pear"}
> 
> local FruitValue = workspace.WorldEvent
> 
> local function Spawner()
> 	local RandomStuff = math.random(1,#Fruits)
> 	local Event = (Fruits[RandomStuff])
> 	
> 	if Event == FruitValue.Value then
> 		-- Duplicate
>     -- make it repeat so it won't pick the same fruit
> 	end
> 	FruitValue.Value = Event
> 	
> 	print(Event)
> end
> 
> 
> while true do
> 	wait(coolown)
> 	Spawner()
> end
1 Like
local cooldown = 3

local Fruits = {"Apples","Orange","Pear"}

local FruitValue = workspace.WorldEvent

local Spawner
Spawner = function()
	local RandomStuff = math.random(1,#Fruits)
	local Event = (Fruits[RandomStuff])
	
	if Event == FruitValue.Value then
		return Spawner()
	end

	FruitValue.Value = Event
	
	print(Event)
	return Event
end


while true do
	task.wait(cooldown)
	Spawner()
end
1 Like