Hello people! I’m currently trying to make a script that will add a point to all players in the server every 15 minutes if the script is enabled… My issue is that when I run the script, it will either give one player the point or it just gives nobody the point. No errors appear in the output box which makes it more confusing, so I chose to upload the whole script right below so you guys can tell me what I did wrong and what to change in it… Thanks, I hope somebody can help me figure this thing out.
if script.Disabled == false then
while true do
for _, v in pairs(game.Players:GetPlayers()) do
wait(900)
v.leaderstats.Commends.Value = v.leaderstats.Commends.Value + 1
end
end
end
Your check to see if script.Disabled is false is redundant as the script won’t run until that property is false anyway.
As for the problem, you have the wait inside your iteration over the players, meaning it’ll be 900 seconds between awarding it for each player. Correct indentation can really help you to see where the problem is in cases like this. Here’s how it should be:
while true do
wait(900)
for _, v in pairs(game.Players:GetPlayers()) do
v.leaderstats.Commends.Value = v.leaderstats.Commends.Value + 1
end
end
that is because you waited 900 seconds and only gave it to one player, and then you wait 900 secs again. Put the wait command before the pairs loop. Then You don’t need the first line. And I would recommend having it as a local script with a remote function. Because let’s say that 870 secs are over and a player joins. That person will get the point in 30 secs. So people would be serverhopping all, over the place.
Does this fix the issue of giving one or zero of the players a point and gives everyone the point like I want it to?
How do I make it give a point to every player in that server?
You just have to move the wait down a line, that’s all