Problem with spawning Props in Tycoon game

Hello Devs I’ve been facing a problem with my Tycoon System, I tried making my own Tycoon system with no docs or tutorials, and I ran into a road block where by I have the Building Template inside Server Storage but when I spawn the Props(Objects) of the building such as tables,lamps…etc I can’t figure out how to place it at the same position as it’s clone in the Template…I know it’s kinda simple but idk lol you guys helping me would help me progress alot. Here’s as snippet of the code

--[[
TODO
 -If player has data then it loads building if not it loads an empty building
]]

local module = {}
local Players   = game:GetService("Players")
local BuildingTemplate = game.ServerStorage:WaitForChild("Model")          -- clone source
local SpawnFolder     = game.Workspace:WaitForChild("BuildSpawnPoints")

--------------------------------------------------------------------
--  Helper ▸ validate the toucher belongs to a Player
--------------------------------------------------------------------
local function characterToplayer(character: Model) :Player?
	if not character then return end
	return Players:GetPlayerFromCharacter(character)
end

----------------------------------------------------------
-- Wire ONE prop-pad so it can spawn / activate its model
----------------------------------------------------------
local function connectPropPad(pad:Part, Prop: Model)
	pad.Touched:Connect(function(hit)
		local PadId = pad:GetAttribute("Id")
		local PropId = Prop:GetAttribute("Id")
		if not PadId then warn("NO ID FOUND FOR THE PAD") end
		print(Prop.Name)
		if PadId == PropId then
			Prop:PivotTo(pad.CFrame)
			Prop.Parent = game.Workspace
			pad:SetAttribute("Occupied", true) 
		end	

	end)
end
----------------------------------------------------------
-- After a building is cloned, wire every prop pad inside it
----------------------------------------------------------
local function wirePropPads(building: Model)
	local Models = building:WaitForChild("Models"):Clone()
	local Points = building:WaitForChild("Points")
	
	if not Models or not Points then
		warn("BUILDING MISSING MODELS OR POINTS FOLDER")
		return
	end
	for _, pad in Points:GetChildren() do
		for _, prop in Models:GetChildren() do
			local Pad = pad
			local Prop = prop
			if Pad:IsA("Part") and Prop:IsA("Model") then
				print("PAD IS PART and Prop is a model")
				connectPropPad(Pad, prop)
			end
		end
	end
end



--------------------------------------------------------------------
--  Helper ▸ place the building template at a pad in workspace
--------------------------------------------------------------------
local function placeBuildingAtPad(pad: BasePart, owner: Player)
	local Clone = BuildingTemplate:Clone()
	Clone.Parent = workspace
	Clone:PivotTo(pad.CFrame)
	Clone:SetAttribute("Owner", owner.UserId)
	pad:SetAttribute("Occupied", true)
	
	-- set up the prop pads for THIS building do
		wirePropPads(Clone)
	
end

--------------------------------------------------------------------
--  Helper ▸ connect ONE pad’s Touched event For BUILDINGS
--------------------------------------------------------------------

local function initPad(pad: BasePart)
	local db = false
	pad.Touched:Connect(function(hitpart)
		if db then return end
		if pad:GetAttribute("Occupied") then return end
		
		local player = characterToplayer(hitpart.Parent)
		if not player then return end
		
		db = true
		placeBuildingAtPad(pad, player)
		db = false
	end)
end

--------------------------------------------------------------------
--  PUBLIC ▸ wire every pad in the folder
--------------------------------------------------------------------

function module.Start()
	for _, pad in SpawnFolder:GetChildren() do
		initPad(pad)
	end
end

return module

1 Like

Okay, first we have to clear up some stuff

-1 Change to Black Theme (please)
-2 Also it should be in the same position as the template? or are u spawning them to their position via script then? could u maybe send a picture how it looks like?
-3 What’s that weird commenting and how u did some spaces?

1 Like

It’s 1 AM and I’m kind of struggling to read your code, but if you have a template of the entire finished tycoon in server storage or whereve,r you can use this code in your placeBuildingAtPad() to figure out the position needed for new objects, relative to their position on the template.

Clone:PivotTo(pad.CFrame:ToWorldSpace(BuildingTemplate.CFrame:ToObjectSpace(TemplateProp:GetPivot())))

I changed some variables to try and match you’re code, but you’re probably going to have to edit it. Hope this helps.

1 Like

Hey sorry for the late reply I was at practice during the day.The placeBuildingAtPad function alreadys works and does what I want it deals with cloning the template of the whole build and placing it to the corresponding pad.

I must be confused about your issue, then. You said that the cloned parts weren’t being positioned in the right place. The code I sent would put them in the same place on the player’s pad, as it is on the template pad. Can you try to clarify your issue?