Hello Developers, So I have this Coin Model and I am trying to randomly spawn the coin model within the radius of this Position(-214., 5, -28) For example the Coin could spawn in -210(X coordinate) or -30(X coordinate)
Here is a visual example
I want the coin to spawn in the red area
The position of the red area is (-214, 5, -28) as I have mentioned before
Here is what I did so far
local StarterZoneCurrency = script.Parent
--(-222,58,-28)
local RandomPosX = math.random(1,214)
local RandomPosY = math.random(1,5)
local RandomposZ = math.random(1,28)- I got an error when I put a negative
local Position = CFrame.new(RandomPosX * -1, RandomPosY, RandomposZ * -1 ) - here I make a variable for the random position I do * -1 to make sure it is negative since I want the coin to spawn in an area that has negative Coordinates. Because when I put a negative value inside the math. random it gave an error
local StarterZoneCurrencyItems = {
StarterZoneCurrency["Bag 1"],
StarterZoneCurrency["Bag 2"],
StarterZoneCurrency["Coin"],
StarterZoneCurrency["Gem"],
StarterZoneCurrency["Chest"]
}
for i,v in pairs(StarterZoneCurrencyItems) do
print(i,v) -- loop through the table to get the coin
if i == 1 then
while true do
wait(0.2)
local CloneBag1 = v:Clone() - clone the Coin
CloneBag1.Parent = game.Workspace - parent the coin
CloneBag1:PivotTo(Positon) - and I postion the coin
end
end
end
There is one problem with this code the Coin does not position randomly it position at this one place.
There is actually like 200 coin in that one position. The Code had no errors just the Coin did not position where I originally intended it to be position