Automatic points not giving to all players on server

I’ve tried making a point system that gives points to every players on the server in certain amount of seconds. However, it doesn’t give to every players and it only works for the first player on the server. If that player leaves, it’ll go to the second player on the server which I don’t know why. This is a server script in serverscriptservice.

local amount = 5
local defaultTime = 10

local timerText = defaultTime

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local currencyTimerEvent = replicatedStorage:WaitForChild("CurrencyTimerEvent")

function updateText()
	currencyTimerEvent:FireAllClients(amount,timerText)
end

while wait(1) do
	timerText -= 1
	updateText()
	
	for _, player in ipairs(players:GetPlayers()) do
		if player and player.Parent and timerText <= 0 then
			timerText = defaultTime
			player.leaderstats.Tots.Value += amount
		end
	end
end
1 Like

change ipairs to pairs it might be work

1 Like

I’ve tried that before, it didn’t work. It just changes the order of v.

1 Like
while wait(1) do
	timerText -= 1
	updateText()
	
	for _, player in ipairs(players:GetPlayers()) do
		if player and player.Parent and timerText <= 0 then
			player.leaderstats.Tots.Value += amount
		end
	end

      timerText = defaultTime
end