I am trying to make a game like noob army tycoon so I am going to have buildings and stuff.
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("ServerButtons") 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
This should get rid of the first error you were getting
But I want to make so that all of the buttons work the same as the server button.
I can’t post the full script so just do this
if buttons then
for i, v in pairs(buttons:GetChildren()) do
if v:FindFirstChild(“Button”) then
spawn(function()
if v:FindFirstChild(“Button”) then
not sure what you mean Could you elaborate a bit more
Like if I add an building button for example. It won’t show because only server buttons show.
Add the line below to the place that is marked (don’t forget to add another end)
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
-- ADD THE LINE BELOW HERE
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
if v:FindFirstChild("Button") then
Then there would be 2 if v:FindFirstChild("Button") then
Oh, I think I understand now, your original script should work.
I think the button isn’t there could you check Button is a child of ServerButtons when you press play
on which line is the error showing?
In the original code it appears on line 47.
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("Buttons") 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
if not v:FindFirstChild("Button") then return print("Does not Exist") 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
Does this print anything?
EDIT: Fixed typo
No, it is not printing anything.
did you try again, I made a typo
Yes. It does not work when I touch it.
Ya. It still does not show the Object and the object still won’t disappear.
could you press play and check if the Button is still there?
It is still there.
just typing (:
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
What error do you get when you try this?
Button is not a valid member of Model “ServerButton”