That is odd, your original error was saying it wasn’t a child of ServerButtons
local tycoon = script.Parent.Parent
local mainItems = tycoon:FindFirstChild("MainItems")
local values = tycoon:FindFirstChild("Values")
local buttons = tycoon:FindFirstChild("Buttons")
local purchasedItems = tycoon:FindFirstChild("PurchasedItems")
local objects = {}
mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
if values.OwnerValue.Value == nil then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if player:FindFirstChild("hasTycoon").Value == false then
values.OwnerValue.Value = player
mainItems.OwnerDoor.Door.SurfaceGui.ClaimText.Text = tostring(values.OwnerValue.Value).."'s Tycoon"
end
end
end
end)
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
coroutine.resume(coroutine.create(function()
if purchasedItems:WaitForChild(v.Dependency.Value) then
v.Button.Transparency = 0
v.Button.CanCollide = 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
I am very confused tbh, the error doesn’t make sense to me. from what I can tell your code is fine and the error is just weird. are you sure it’s not being destroyed or anything?
Could you explain what “Dependency” is? I also tidied up your code and got rid of a part that may have caused the error.
Code:
local Players = game:GetService("Players")
local tycoon = script.Parent.Parent
local mainItems = tycoon.MainItems
local values = tycoon.Values
local buttons = tycoon.Buttons
local purchasedItems = tycoon.PurchasedItems
mainItems.OwnerDoor.Door.Touched:Connect(function(hit)
if values.OwnerValue.Value then
return
end
local player = Players:GetPlayerFromCharacter(hit.Parent)
local hasTycoon = player and player:FindFirstChild("hasTycoon")
if hasTycoon and not hasTycoon.Value then
values.OwnerValue.Value = player
mainItems.OwnerDoor.Door.SurfaceGui.ClaimText.Text = player.Name .."'s Tycoon"
end
end)
for i, v in buttons:GetChildren() do
task.spawn(function()
if not v:FindFirstChild("Button") then
return
end
local newObject = purchasedItems:FindFirstChild(v.Object.Value)
local clonedObject = nil
if newObject then
clonedObject = newObject:Clone()
newObject:Destroy()
else
v:Destroy()
return
end
v.Button.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
local leaderstats = player and player:FindFirstChild("leaderstats")
if leaderstats and leaderstats.Cash.Value >= v.Price.Value and values.OwnerValue.Value == player and v.Button.CanCollide then
leaderstats.Cash.Value -= v.Price.Value
clonedObject.Parent = purchasedItems
v:Destroy()
end
end)
end)
end