I want it so that for every model named "Plant" gives 100 "Credits" per 1.5 seconds.
I have the actual money giving script done and perfect, it gives 10 credits every 1.5 seconds, now I want it to add 150 more credits per Plant that exists simultaneously in game.
I have it to where it prints whatever the value of "amount" is every time it adds Credits, it just continuously adds 150 to the already existing 150 making it go up to numbers like 1000 within seconds, this is because it is in a loop, but the script doesn't actually work unless it is in the loop.
Heres the script:
amount = 10 timedelay = 1.5 currencyname = "Credits" teamcore = 0 -- ignore this while true do wait(timedelay) for i,v in pairs(game.Players:GetPlayers()) do if v:FindFirstChild("leaderstats") then v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value + amount local cash = workspace:FindFirstChild("Plant") if cash then yes = true if yes == true then amount = amount + 150 print(amount) end end end end end
any help please?
Try using Instance:GetDescendants() function, returns an array that contains all descendants of selected object. FYI:
https://developer.roblox.com/en-us/api-reference/function/Instance/GetDescendants
local Models = game.Workspace:GetDescendants() -- up to you local Plants = {} for i, model in pairs(Models) do if model:IsA("Model") then if model.Name == "Plant" then table.insert(Plants, model) end end end print("There are " ..#Plants) -- prints how many plants are in your game.
PS: If this meant to count a player's owned plant then put this in a local script and tell the server by using remote events/functions.