Random Build Generator Not Working

So I’m creating a generator that grabs a random Dungeon inside a Folder within the ReplicatedStorage and then puts that Dungeon into the game. The Dungeon will generate on top of a specific Part that is somewhere on the map. Currently, the output is returning an error that says “Unable to cast double to CoordinateFrame”.

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local DungeonGenerators = game.Workspace.DungeonGenerators:GetChildren()
local GeneratedDungeons = game.Workspace.GeneratedDungeons
local Dungeons = ReplicatedStorage.Dungeons
local Chest = ReplicatedStorage.Chest

local GeneratableDungeons = {
	["Dungeon1"] = 1;
	["Dungeon2"] = 2;
	["Dungeon3"] = 3;
	["Dungeon4"] = 4

local GenDungeonsYPos = {
	[8.5] = "Dungeon1";

-- local DungeonNumberGen (IGNORE THIS)
local SelectedDungeons = {"Dungeon1", "Dungeon1"}

--[[for Count = 1,table.getn(DungeonGenerators) do
	DungeonNumberGen = math.random(1,table.getn(DungeonGenerators))
	for DungeonTemplate,DungeonKey in pairs(GeneratableDungeons) do
		if DungeonNumberGen == DungeonKey then
			table.insert(SelectedDungeons, DungeonKey, DungeonTemplate)
			print('Dungeon' .. DungeonKey .. ' Generated!') --Debug
]]-- Ignore all of this

local function GenerateDungeon(Dungeon, DungeonCFrame, GenerateObject)
	local DungeonBuild = Dungeons:FindFirstChild(Dungeon):Clone()
	DungeonBuild:SetPrimaryPartCFrame(GenerateObject.Position.x, DungeonCFrame, GenerateObject.Position.z) --Error
	DungeonBuild.Parent = GeneratedDungeons

for i = 1,table.getn(SelectedDungeons) do
	local Dungeon = SelectedDungeons[i]
	for DungeonCFrame,DungeonChecker in pairs(GenDungeonsYPos) do
		if Dungeon == DungeonChecker then
			GenerateDungeon(Dungeon, DungeonCFrame, DungeonGenerators[i]) --Error

So , it should go through all the Dungeon names in the table ‘SelectedDungeons’ and compare them to the name of the Dungeons in the table ‘GenDungeonsYPos’. If there is a match then it will use the ‘GenerateDungeon’ function to spawn the Dungeon on the map using the Dungeon’s name, YPos (this is so that when the dungeon is spawning into the game, it will spawn on the X and Z coordinates of the Dungeon Generator Object but the Y is supposed to be equal to half of the Dungeon’s height), and the Dungeon Generator Object.

The GenerateDungeon() function then is supposed to set the CFrame of the selected Dungeon and then put it into the Workspace.

Did you set a primary part for the Model?

Yes, I have the primary part set before setting the Dungeon as generatable. Although I don’t do it using a script.

SetPrimaryPartCFrame takes one argument, which is a cframe. You are giving it three numbers. You should instead give those three numbers to CFrame.new() and give the returned cframe to SetPrimaryPartCFrame.

DungeonBuild:SetPrimaryPartCFrame(CFrame.new(GenerateObject.Position.x, DungeonCFrame, GenerateObject.Position.z))