So I followed this tycoon tutorial videos and now I’m stuck with this problem.
local tycoon = script.Parent.Parent
local mainItems = tycoon:FindFirstChild("MainItems")
local values = tycoon:FindFirstChild("Values")
local buttonsFolder = tycoon:FindFirstChild("Buttons")
local purchasedItems = tycoon:FindFirstChild("PurchasedItem")
local objectStorage = tycoon:FindFirstChild("PurchaseObjects") -- NEW!
local objects = {}
-- Claim tycoon ownership
mainItems.Ownerdoor.Door.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and values.OwnerValue.Value == nil then
local hasTycoon = player:FindFirstChild("HasTycoon")
if hasTycoon and hasTycoon.Value == false then
values.OwnerValue.Value = player
hasTycoon.Value = true
mainItems.Ownerdoor.Title.SurfaceGui.TextLabel.Text = player.Name .. "'s Tycoon"
end
end
end)
-- Function to set up a single button
local buttons = tycoon:FindFirstChild("Buttons")
local purchasedItems = tycoon:FindFirstChild("PurchasedItems")
local objects = {}
if buttons then
for i, v in pairs(buttons:GetChildren()) do
spawn(function()
if v:FindFirstChild("Button") then
local newObject = purchasedItems:FindFirstChild(v.Object.Value)
if newObject ~= nil then
objects[newObject.Name] = newObject:Clone()
newObject:Destroy()
else
v:Destroy()
end
if v:FindFirstChild("Dependency") then
v.Button.Transparency = 1
v.Button.CanCollide = false
v.Button.BillboardGui.Enabled = false
coroutine.resume(coroutine.create(function()
if purchasedItems:WaitForChild(v.Dependency.Value) then
v.Button.Transparency = 0
v.Button.CanCollide = true
v.Button.BillboardGui.Enabled = true
end
end))
end
v.Button.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if values.OwnerValue.Value == player then
if v.Button.CanCollide == true then
if player:FindFirstChild("leaderstats").Cash.Value >= v.Price.Value then
player.leaderstats.Cash.Value -= v.Price.Value
objects[v.Object.Value].Parent = purchasedItems
v:Destroy()
end
end
end
end
end)
end
end)
end
end