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
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.
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.