Hello all!
This function I wrote is intended to move along a list of folders (that contain tycoon buttons). However, when I run the script and try it out in game it does reveal the buttons within the next folder in the list, but after I buy the first button the MPS doesn’t increase. The output also doesnt print "Child removed from"
when I destroy one of the buttons within the folder which makes me think that the childremoved isnt even recognizing when one of the buttons gets removed. Here is the entire code:
local Buttons = {}
local Team = script.Parent.SpawnLocation.TeamColor
local player = nil
local totalButtons = 1
local BuyParts = script.Parent.CargoContainer:GetChildren()
local Folders = {script.Parent.CargoContainer1, script.Parent.CargoContrainer1Shops}
local currentFolder = 1
local MPS = 0
game.Teams["Vorld Wision"].PlayerAdded:Connect(function(plr)
player = plr
end)
function Buttons.Appear(mod)
for _, v in pairs(mod:GetDescendants()) do
if v:IsA("Part") or v:IsA("MeshPart") then
if v.Name ~= "HumanoidRootPart" then
v.Transparency = 0
v.CanCollide = true
v.CanTouch = true
end
end
end
end
function Buttons.CheckIfCanBuy(Cost, plr)
if (game.Players:GetPlayerFromCharacter(plr.Parent).TeamColor == script.Parent.SpawnLocation.TeamColor) and (game.Players:GetPlayerFromCharacter(plr.Parent).leaderstats.Money.Value >= Cost) then
game.Players:GetPlayerFromCharacter(plr.Parent).leaderstats.Money.Value = game.Players:GetPlayerFromCharacter(plr.Parent).leaderstats.Money.Value - Cost
return true
else
return false
end
end
function Buttons.FindOwner()
return player
end
function Buttons.RevealButton(Folder) --the group of buttons you want to make appear
for _, v in pairs(Folder:getChildren()) do
for _, v in pairs(Folder:getDescendants()) do
if v:IsA("Part") then
v.Transparency = 0
v.CanCollide = true
v.CanTouch = true
else if v:IsA("BillboardGui") then
v.Enabled = true
end
end
end
end
end
function MPSS()
while true do
task.wait(5)
print("MPS Fired")
player:WaitForChild("leaderstats").Money.Value += MPS
end
end
Buttons.Appear(Folders[1].ABuyButton) -- for testing purposes, this is just to spawn in the first button for the chain
Folders[currentFolder].ChildRemoved:Connect(function()
if #Folders[currentFolder]:GetChildren() == 0 then
currentFolder += 1
Buttons.RevealButton(Folders[currentFolder])
print(Folders[currentFolder])
end
print("Child removed from")
print(Folders[currentFolder])
if Folders[currentFolder] == script.Parent.CargoContrainer1Shops then
MPS += 100
print("MPS INCREASED")
end
end)
local never = true
local thread = coroutine.create(MPSS)
game.Teams["Vorld Wision"].PlayerAdded:Connect(function()
coroutine.resume(thread)
end)
return Buttons
This is the specific function thats giving me trouble
Folders[currentFolder].ChildRemoved:Connect(function()
if #Folders[currentFolder]:GetChildren() == 0 then
currentFolder += 1
Buttons.RevealButton(Folders[currentFolder])
print(Folders[currentFolder])
end
print("Child removed from")
print(Folders[currentFolder])
if Folders[currentFolder] == script.Parent.CargoContrainer1Shops then
MPS += 100
print("MPS INCREASED")
end
end)
Any help is appreciated (so is an explanation)