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”.
--//SERVICES//--
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--//OBJECT VARIABLES//--
local DungeonGenerators = game.Workspace.DungeonGenerators:GetChildren()
local GeneratedDungeons = game.Workspace.GeneratedDungeons
local Dungeons = ReplicatedStorage.Dungeons
local Chest = ReplicatedStorage.Chest
--//VALUE VARIABLES//--
local GeneratableDungeons = {
["Dungeon1"] = 1;
["Dungeon2"] = 2;
["Dungeon3"] = 3;
["Dungeon4"] = 4
}
local GenDungeonsYPos = {
[8.5] = "Dungeon1";
}
-- local DungeonNumberGen (IGNORE THIS)
local SelectedDungeons = {"Dungeon1", "Dungeon1"}
--//EXECUTION//--
--[[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
end
end
end
]]-- 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
end
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
end
end
end
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.