-
What do you want to achieve? Keep it simple and clear!
So basically i’m making an tycoon game. I’m using B Ricey tutorial for it. For some strange reason while i’m loading data and destroy button(Like in tutorial #8) it just gives me error with loading component , but it shouldn’t. Note this is not components problem in case it worked without despawn function and tag -
What is the issue? Include screenshots / videos if possible!
Described in first, here is screenshoot:

-
What solutions have you tried so far? Did you look for solutions on the Developer Hub? I was making this by youtube video and it should work
Despawn module code:
local Despawn = {}
Despawn.__index = Despawn
function Despawn.new(tycoon, instance)
local self = setmetatable({}, Despawn)
self.Tycoon = tycoon
self.Instance = instance
end
function Despawn:Init()
self.Tycoon:SubscribeTopic("Button", function(id)
if id == self.Instance:GetAttribute("Id") then
self.Instance:Destroy()
end
end)
end
return Despawn
Code which get error:
local CollectionService = game:GetService("CollectionService")
local template = game:GetService("ServerStorage").Template
local componentFolder = script.Parent.Components
local tycoonStorage = game:GetService("ServerStorage").TycoonStorage
local playerManager = require(script.Parent.PlayerManager)
local function NewModel(model, cframe)
local newModel = model:Clone()
newModel:PivotTo(cframe)
newModel.Parent = workspace
return newModel
end
local Tycoon = {}
Tycoon.__index = Tycoon
function Tycoon.new(player, spawnPoint)
local self = setmetatable({}, Tycoon)
self.Owner = player
self._topicEvent = Instance.new("BindableEvent")
self._spawn = spawnPoint
return self
end
function Tycoon:Init()
print(self._spawn)
self.Model = NewModel(template, self._spawn.CFrame)
self._spawn:SetAttribute("Occupied", true)
self.Owner.RespawnLocation = self.Model.Spawn
self.Owner:LoadCharacter()
self:LockAll()
self:LoadUnlocks()
self:WaitForExit()
end
function Tycoon:LoadUnlocks()
for _, id in ipairs(playerManager.GetUnlockIds(self.Owner)) do
self:PublishTopic("Button", id)
end
end
function Tycoon:LockAll()
for _, instance in ipairs(self.Model:GetDescendants()) do -- Here is error
if CollectionService:HasTag(instance, "Unlockable") then
self:Lock(instance)
else
self:AddComponents(instance)
end
end
end
function Tycoon:Lock(instance)
instance.Parent = tycoonStorage
self:CreateComponent(instance, componentFolder.Unlockable)
end
function Tycoon:Unlock(instance, id)
playerManager.AddUnlockId(self.Owner, id)
CollectionService:RemoveTag(instance, "Unlockable")
self:AddComponents(instance)
instance.Parent = self.Model
end
function Tycoon:AddComponents(instance)
for _, tag in ipairs(CollectionService:GetTags(instance)) do
local component = componentFolder:FindFirstChild(tag)
if component then
self:CreateComponent(instance, component)
end
end
end
function Tycoon:CreateComponent(instance, componentScript)
local compModule =require(componentScript)
local newComp = compModule.new(self, instance)
newComp:Init() -- here is an problem
end
function Tycoon:PublishTopic(topicName, ...)
self._topicEvent:Fire(topicName, ...)
end
function Tycoon:SubscribeTopic(topicName, callback)
local connection = self._topicEvent.Event:Connect(function(name, ...)
if name == topicName then
callback(...)
end
end)
return connection
end
function Tycoon:WaitForExit()
playerManager.PlayerRemoving:Connect(function(player)
if self.Owner == player then
self:Destroy()
end
end)
end
function Tycoon:Destroy()
self.Model:Destroy()
self._topicEvent:Destroy()
self._spawn:SetAttribute("Occupied", false)
end
return Tycoon
Yeah this is 7th topic already, but i have no freaking idea why i always get error on each video.

