Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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
Ad

Answer this question