I’m trying to create a system that spawns ores randomly in a certain area, but, they’re all seemingly spawning on one part, versus the many available. What could be the fix to such an issue?
local result = Roll()
local spawnBricks = game.Workspace.Spawns:GetChildren()
local Index = math.random(#spawnBricks)
local Chosen = spawnBricks[Index]
local InitializeOre = 6
local FoundLocation = Spawns:FindFirstChild(Chosen.Name)
local function OreSpawn()
local IsOccupied = Chosen.Occupied.Value
if not IsOccupied then
for i = InitializeOre, 0, -1 do
if result == "Rock" then
local rockClone = Ores[1]:Clone()
rockClone.Parent = FoundLocation
rockClone:PivotTo(FoundLocation.CFrame)
rockClone.Parent.Occupied.Value = true
elseif result == "IronOre" then
local ironClone = Ores[2]:Clone()
ironClone.Parent = FoundLocation
ironClone:PivotTo(FoundLocation.CFrame)
ironClone.Parent.Occupied.Value = true
elseif result == "GoldOre" then
local goldClone = Ores[3]
goldClone.Parent = FoundLocation
goldClone:PivotTo(FoundLocation.CFrame)
goldClone.Parent.Occupied.Value = true
elseif result == "AzureOre" then
local azureClone = Ores[4]:Clone()
azureClone.Parent = FoundLocation
azureClone:PivotTo(FoundLocation.CFrame)
azureClone.Parent.Occupied.Value = true
end
end
end
end
Players.PlayerAdded:Connect(OreSpawn)
for _, player in game.Players:GetPlayers() do
task.spawn(OreSpawn)
end
function Roll()
local CurrentBestRarity = "Rock"
for RarityTier, Chance in OreArray do
local NewRoll = Rand:NextNumber()
if NewRoll < Chance then
if OreArray[CurrentBestRarity] > Chance then
CurrentBestRarity = RarityTier
end
end
end
function Roll()
local CurrentBestRarity = "Rock"
for RarityTier, Chance in OreArray do
local NewRoll = Rand:NextNumber()
if NewRoll < Chance then
if OreArray[CurrentBestRarity] > Chance then
CurrentBestRarity = RarityTier
end
end
end
return CurrentBestRarity
end
local result = Roll()
local spawnBricks = game.Workspace.Spawns:GetChildren()
local InitializeOre = 6
local function OreSpawn()
local Index = math.random(#spawnBricks)
local Chosen = spawnBricks[Index]
print(Index)
print(Chosen)
local FoundLocation = Spawns:FindFirstChild(Chosen.Name)
print(FoundLocation)
local IsOccupied = Chosen.Occupied.Value
if not IsOccupied then
for i = InitializeOre, 0, -1 do
if result == "Rock" then
local rockClone = Ores[1]:Clone()
rockClone.Parent = FoundLocation
rockClone:PivotTo(FoundLocation.CFrame)
rockClone.Parent.Occupied.Value = true
elseif result == "IronOre" then
local ironClone = Ores[2]:Clone()
ironClone.Parent = FoundLocation
ironClone:PivotTo(FoundLocation.CFrame)
ironClone.Parent.Occupied.Value = true
elseif result == "GoldOre" then
local goldClone = Ores[3]
goldClone.Parent = FoundLocation
goldClone:PivotTo(FoundLocation.CFrame)
goldClone.Parent.Occupied.Value = true
elseif result == "AzureOre" then
local azureClone = Ores[4]:Clone()
azureClone.Parent = FoundLocation
azureClone:PivotTo(FoundLocation.CFrame)
azureClone.Parent.Occupied.Value = true
end
end
end
end
Players.PlayerAdded:Connect(OreSpawn)
When the function spawns it chooses a part and take it position and thats all, only a single part. I will go to my pc and remake it a bit and give it to you