Help with randomly generating a sequence of weapons

So you are sure that you have the right table? If you are then it might be I guess.

You could try getDescendants() and see if that does anything. Maybe it won’t show folders but will show the tools inside.

I think I have an idea, what if we use module scripts?
But I have limited experience with them.

EDIT: I manged to get a module script working, but same problem. The script won’t detect the if statement resulting with error

My new Idea:

What if we create a new table, every time a weapon is picked, the weapon will be put in this table, and if we get what’s inside of this table, we will reroll until something new, and when the table is full, we could simply just empty it.

though, I need some helping making this.

Hmm its weird that it wont work.

That is the original thing I did, before I rewrote it with just removing stuff from the table.

error

https://gyazo.com/e6344f0d6f39d5b7110321cafac368eb

this is lua not python, what :joy:

1 Like

I was wondering why it didn’t work :laughing:

EDIT: @D0RYU how can we make this work then?

local usedWeps = {}

local WepTheme = game.ServerStorage.Weapons:GetChildren()
local ChosenWepTheme = nil
repeat
    ChosenWepTheme = WepTheme[math.random(1, #WepTheme)] 
until not usedWebs[ChosenWepTheme]

table.insert(usedWeps, ChosenWepTheme)

local weps = ChosenWepTheme:GetChildren()

so I converted his script into lua

Thanks, I will test this and let you know. :slight_smile:

Edit: what if every weapon in wepthemes is in used weps?
@D0RYU ?

chosen wep theme is not defined for some reason
https://gyazo.com/c2dc73c9f7eb7f825f28671f7a2c67df
picture ^^^

let me edit the reply from earlier, my bad

EDIT: use table.clear() to clear the table if all weapons have been used

how will I check if every weapon is in usedweps?

if #usedWeps == #WepTheme then

end

my current script:
it’s not working, I got the same weapon twice.

-- Outside the game loop
local WepTheme = game.ServerStorage.Weapons:GetChildren()
-- Inside the game loop

	local usedWeps = {}

	local ChosenWepTheme = nil
	
	if #usedWeps == #WepTheme then
		for k in pairs (usedWeps) do
			usedWeps [k] = nil
		end

	end

	repeat
		ChosenWepTheme = WepTheme[math.random(1, #WepTheme)] 
	until not usedWeps[ChosenWepTheme]

	table.insert(usedWeps, ChosenWepTheme)

	local weps = ChosenWepTheme:GetChildren()
	local ChosenWepTheme = nil
	
	if #usedWeps == #WepTheme then
		table.clear(usedWeps)
	end

	repeat
		ChosenWepTheme = WepTheme[math.random(1, #WepTheme)] 
	until not usedWeps[ChosenWepTheme]

	table.insert(usedWeps, ChosenWepTheme)

	local weps = ChosenWepTheme:GetChildren()

use that in the loop and put

local usedWeps = {}

outside the loop with the :GetChildren() table

doesn’t seem to be working, I got the same weapon twice, no errors

can I see the full code?
that would help

EDIT: also I forgot a parentheses on the table.clear line, you said you had no errors so you probably fixed that

my personal guess is this line that’s causing the issue

change this to

until usedWeps[ChosenWepTheme] == nil

Result:

The script kept on going and going and going and going

what I mean is it did start the round but didn’t give the weapon and no errors

oh yea sorry I edited, that was a minor mistake on my part