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