what line and before you leave the game send a screenshot of the server buttons
Line 48 and
i meant a screenshot of server buttons and it’s children while the error occurs like in workspace
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?
I think it destroys cause it thinks there is supposed to be a dependency and there is supposed to be one in future buttons.
that is probably the issue, try removing the code or just commenting out the destroy bit and then try it
That was the problem. But the button does not work.
try printing after the touched event to see if it detects the touch, add prints after each statement to see where the code breaks
Before I touched it I got this Inf Yeild: Infinite yield possible on 'Workspace.Tycoons.Tycoon.PurchasedItems:WaitForChild(“Server1”)
From a earlier screenshot you sent there is nothing inside the folder “PurchasedItems” so that’s why it probably yielded
Yes but it does this objects[v.Object.Value].Parent = purchasedItems
then I don’t think that is working
Should I do v.Parent = purchasedItems
EDIT: I realised it won’t work
That I do not know since I don’t know what
is
nvm…
asjdasjlkdjaslkdjasiodu aiwodhjauiwoyhd
I know it’s something with the destroy.
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
I want a dependency for other parts.