I'm trying to make a plugin where it generates an empty house randomly, there are gonna be 3 houses.
How would I make be a random house each time I click it?
assets = {"168573570","168574001"} rhouse = game:GetObjects("rbxassetid://ID")
What we want is to get a random value from assets
when all we can do is generate random numbers using math.random
.
So, where are numbers in this problem that we could ask for with math.random
? The numbers in this situation are the indices of assets
, e.g., assets[1]
is "168573570"
and assets[2]
is "168574001"
.
So we just generate a random index from assets
and use the asset at that index.
local randomAssetIndex = math.random(1, #assets); -- Pick a random number [1, 2, .. , length of `assets`] local randomAsset = assets[ randomAssetIndex ]; rhou = game:GetObjects("rbxassetid://" .. randomAsset);
Note that the quotes on your assets aren't necessary, just to save a bit of typing. Whenever you concatenate the conversion number -> string is done automatically, and since they are always proper numbers, there's no need to quote them.