Give player currency based on TimeOfDay

Hello!
Within my game, I have a currency system ready to go, and I’d like to make it so the player is rewarded 25 coins everytime it hits 6am within the game (server wide).
Since I am new to scripting and used a tutorial for the currency system, I am unsure how to set it up to do this.
Here is my script so far with what I’ve tried:

local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")

local DataStore2 = require(1936396537)

local defaultamount = 0

players.PlayerAdded:Connect(function(player)
	local currencystore = DataStore2("Fazcoins", player)
	
	local function playercurrency(amount)
		RS.RemoteEvents.PlayerCurrency:FireClient(player, amount)
	end
	
	playercurrency(currencystore:Get(defaultamount))
	
	currencystore:OnUpdate(playercurrency)
end)

while game.Lighting.ClockTime(6) do
	for k, v in pairs(players:GetChildren()) do
		local currencystore = DataStore2("Fazcoins", v)
		
		currencystore:Increment(25)
	end
end

Thanks for any help!

try making it check it the clock time ever is 6 by doing game.Lighting.ClockTime == 6
I may be wrong

Where would it be best to put that line of code?
And what would I put in place of “while game.Lighting.ClockTime(6) do”?
I’m very new to scripting so a lot of this is foreign to me, I’m learning as I go.

Do not use players:GetChildren(), use players:GetPlayers()

Fixed script here. It is better to use GetPlayers on the Players service rather than GetChildren.

Try this:

local function pay_players()
	for k, v in pairs(players:GetPlayers()) do
		local currencystore = DataStore2("Fazcoins", v)
		
		currencystore:Increment(25)
	end
end

game.Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
	if game.Lighting.ClockTime == 6 then
		pay_players()
	end
end)

Bear in mind, the code will only execute when the ClockTime is exactly 6, so if your system is more analog, it may need reworking.

Hey, we got the same idea! :highfive: Why isn’t this an emote yet…?

Just looking at that I think it’s going to work. I’ll give it a go when I can tomorrow, thank you!
If it doesn’t work I’ll let you know.