Issue with Cloning a part [UNSOLVED]

local function BringPlayer(player, position)
	local character = player.Character
	if character then
		local spawnOffset = Vector3.new(0, 5, 0)
		character:SetPrimaryPartCFrame(CFrame.new(position + spawnOffset))
	end
end
local function CreateBlock(Vector,Type,parent)
	local block = workspace[Type]
	print(block.Name)
	if block then
		local clone = block:Clone()
		clone.Parent = parent
		clone.Position = Vector3.new(Vector)
	else
		warn("Block not found.")
	end
end
local function CreateSkyblockIsland(plr)
	local island = workspace.Skyblock.PlayerCopyIsland:Clone()
	island.Name = plr.Name.."_skyblock"
	island.Parent = workspace.Skyblock
	local Folder = island
	local Inside = Folder:GetChildren()
	local X = math.random(-1000, 1000)
	local Y = math.random(-20, 20)
	local Z = math.random(-1000, 1000)
	wait(2)
	for _, Search in ipairs(Inside) do
		if Search:IsA("Part") then
			if Search.Name == "StoneBlock" then
				if math.random() >= 0.3 then
					print("Same")
				else
					CreateBlock(Search.Position,"CoalOreBlock",island)
					Search:Destroy()
				end
			end
			local offset = Vector3.new(X, Y, Z)
			local newPosition = Search.CFrame.Position + offset
			Search.CFrame = CFrame.new(newPosition)
		end
	end
	local spawnBlock = island:FindFirstChild("SpawnBlock")
	if spawnBlock then
		BringPlayer(plr, spawnBlock.CFrame.Position)
		print("Spawn Block Found")
	end
end

local function DeleteSkyblockIsland()
	print("Hi")
end

game.Players.PlayerAdded:Connect(CreateSkyblockIsland)
game.Players.PlayerRemoving:Connect(DeleteSkyblockIsland)

The code is supposed to generate a new island with a 30% of each stone block having a CoalOreBlock. It’s logging everything correctly. But when the 30% is met, there is nothing there.

Summary:

My code is destorying the block, but not generating the new one, It prints fine

1 Like

I don’t think math.random could go into decimals. Try dividing the result by 10

1 Like

try using Random.new()

1 Like

That’s not the issue. It is getting a 30%, It’s deleting the block that is there, but not placing a new block.

1 Like