Hello all! I am having a bit of trouble with finding out a way to give the player money per second based on how many workers they have I honestly have no idea how to go about this so any help would be apreciated.
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
local function MPSS()
while true do
task.wait(5)
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])
end
print(Folders[currentFolder])
print(currentFolder)
if Folders[currentFolder] == script.Parent.CargoContrainer1Shops then
MPS += 100
print("MPS INCREASED")
end
end)
local never = true
local thread = coroutine.wrap(MPSS)
thread()
return Buttons
This is the main script within every tycoon model. Near the bottom you can see that I attempted to use coroutine.wrap
to try and run a loop that adds money for the player every couple of seconds without stopping the rest of the code. The issue is that when I update MPS, I don’t think the actual MPSS
function is updating. Again, I’m open to all ideas so any help would be appreciated. (an explanation would also be appreciated)