Hello, I want for ma game a leaderstats which take every minute in-game and give 10Skycoins by minute.
All work good, only it don’t save when I leave and reconnect.
Here my script, I m kinda bad at it, so maybe its something really simple to fix but please help.
local DataStoreService = game:GetService("DataStoreService")
local DataStoreT = DataStoreService:GetDataStore("TimeStats")
local DataStoreC = DataStoreService:GetDataStore("SkyCoinStats")
game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new("Folder")
Leaderstats.Name = "leaderstats"
Leaderstats.Parent = Player
local Minutes = Instance.new("IntValue")
Minutes.Name = "Minutes"
Minutes.Value = 0
Minutes.Parent = Leaderstats
local SkyCoins = Instance.new("IntValue")
SkyCoins.Name = "SkyCoins"
SkyCoins.Value = 0
SkyCoins.Parent = Leaderstats
local Data = DataStoreT:GetAsync(Player.UserId)
if Data then
Minutes.Value = Data
end
local Date = DataStoreC:GetAsync(Player.UserId)
if Data then
SkyCoins.Value = Data
end
coroutine.resume(coroutine.create(function()
while true do
wait(60)
Minutes.Value = Minutes.Value + 1
SkyCoins.Value = SkyCoins.Value + 10
end
end))
end)
game.Players.PlayerRemoving:Connect(function(Player)
DataStoreT:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
DataStoreC:SetAsync(Player.UserId, Player.leadestats.SkyCoins.Value)
end)
Thanks for all helps !