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

Choose A Random Pet From A table?

local RP = game.ReplicatedStorage
local Directory = {
Pets = {
["Dog"] = {
	Name = "Dog",
	Rarity = "Common",
	Level = "1"
},
["Cat"] = {
	Name = "Cat",
	Rarity = "Common",
	Level = "1"
	}
}
}
RP["OpenEgg"].OnServerEvent:Connect(function(plr, arg1, arg2)
	local Pet = Directory.Pets[math.random(1, #Directory.Pets)]
	print(Pet)
end)

its telling me #Directory.Pets is 0 when it clearly isnt

2 comments

0

These answers are horrible, feel bad for you man, try #Directory.Pets:GetChildren()

2 answers

rather then using math.random i prefer to use the Random.new()

for example

local rng = Random.new()

print(rng:NextInteger(5, 10))
-- will print a value between 5 and 10

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