When i started out developing i looked up a YouTube tutorial for a cash riser. Recently i have been revamping my game and wanted to make it so if you are on the Donut Shop Worker team you get money and if your on some other team like boys you dont.(Kind of like The Neighborhood Of Robloxia, the one made by Q_Q, where if your are on the SWAT team you get money and if your are on the teen team you dont.)
Here is the script, i tried a if game.Teams.DonutShopWorker then statement, but it didn’t work.
amount = 25
timedelay = 10
currencyname = "Cash"
while true do
wait(timedelay)
for i,v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("leaderstats") and v then
v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value+ amount
end
end
end
1 Like
Try
if Player.Team == game:GetService("Teams")["TeamName"] then
Also you will need to check if v is a thing before doing FindFirstChild (not necessary just makes more sense)
1 Like
Player in if Player.Team == game:GetService("Teams")["TeamName"] then becomes a unknown global once the end is added. i think i have to assign it to the player but i dont think i really know how to do that.
1 Like
Considering this is what your script looks like, I’m very scared about you making multiple copies of this script to assign time.
Although there are other bones to pick with this code, let’s just focus on the main issue of the script - how to do this at all.
So, simply put, all you’ll want to do is store a table of your jobs and what amount should be given to them. That’s it. Here’s an example:
local Teams = game:GetService("Teams")
local Wages = {
["Donut Shop Worker"] = {Pay = 25, Interval = 10}
}
for Team, Data in pairs(Wages) do
coroutine.wrap(function ()
while true do
wait(Data.Interval)
for _, Player in pairs(Teams[Team]:GetPlayers()) do
-- Leaderstats thing here
end
end
end)()
end
It’s not a clean example and surely needs work, though this is what I could whip up for now. It’s all about thinking about the problem, what API you need to accomplish it and how to organise your code to reach your goal.
One thing for the future: when you’re familiar with them, try moving data to a ModuleScript. Only use leaderstats to display, not as actual data values.
5 Likes
what wrong with that end the one that is end)() it breaks the script
1 Like
Considering that’s how coroutine.wrap works, this shouldn’t error. Did this occur after you added your edits or is it what I wrote itself? Providing your current code and the full error message would be helpful.
1 Like
its once i added the leaderstats thing i guessing it has to do with the v
local Teams = game:GetService(“Teams”)
local Wages = {
["Donut Shop Worker"] = {Pay = 25, Interval = 10}
}
for Team, Data in pairs(Wages) do
coroutine.wrap(function ()
while true do
wait(Data.Interval)
for _, Player in pairs(Teams[Team]:GetPlayers()) do
if v:FindFirstChild("leaderstats") and v then
v.leaderstats[currencyname].Value = v.leaderstats[currencyname].Value+ amount
end
end
end)()
end
and then the
You forgot an extra end after you change the leaderboard stats and used the wrong variables. Remember to read the code and work around what’s been given.
local Wages = {
["Donut Shop Worker"] = {Pay = 25, Interval = 10}
}
for Team, Data in pairs(Wages) do
coroutine.wrap(function ()
while true do
wait(Data.Interval)
for _, Player in pairs(Teams[Team]:GetPlayers()) do
if Player:FindFirstChild("leaderstats") then
Player.leaderstats[currencyname].Value = Player.leaderstats[currencyname].Value+ Data.Pay
end
end
end
end)()
end
Not sure what’s going on with the indentation. You can fix that later via Studio.
1 Like
thank you so much. I am learning scripting each day. i am going to look up coroutine.wrap is so i have a better understanding for the future if i ever need it again.