Why are all parts only parenting to a singular part?

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?
image

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

The ore within are also the same type, regardless of the wide selection of ores that could spawn.
image
f61e0265bd77134e5be1bcf4c5a613417bf070c5

You made index at the start of the script so it will choose a number and never change it again

What could be an alternative? Since I’m rather new at scripting.

Move index and chosen to the ore spawn function

Should I move FoundLocation as well?

1 Like

Yea, i forgot about it, limit limit limit

image
Hm… It’s still seemingly doing the same thing

Wait… i was just trying to explain you and noticed that all parts in Spawns have the same name? Maybe change the names?

Unfortunately, this wasn’t the case.
image

Also,

This code means that every time a player joins it will mane new ores per player.

This line is simply for testing purposes, but, I’ll remove it to make sure that this issue has been dealt with.

1 Like

Try printing index chosen and found location and show the output

Also what is result, i don’t realy understand

image

Here’s the print with index, chosen and foundlocation.
image

It’s a reference to this

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
1 Like

I hope i don’t feel annoying but can you show updated version of your script

Sure!

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