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

How do I make a coin/item generator with random positions?

I have a script, and I am trying to make it load in random piles of coins. I tried to use vector3 and math.random to make it, and it works fine, but in math.random I can only go higher than 2, and I can't go to math.random(1,2,3) Script:

coins = game.ReplicatedStorage.CoinPile

while true do
	wait (1)
	local part = coins:Clone()
	part.Parent = workspace
	part.Position = Vector3.new(math.randomseed(1,2), 1.2, math.random(1,2))
end

Any help?

1 answer

✓ Accepted answer

math.random has two arguments: The minimum number, and the maximum number. Just use math.random(1,3) where 1 is the minimum possible number, and 3 is the maximum possible number. Additionally, if you wanted your possible positions to be more defined, you could do something like this:

print(math.random(10,30)/10) -----------> This would result in a number between 1 and 3, but it is now more defined because a digit now has a possibility to fall in the tenths place. For example, 1.2 or 2.5

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