Hi! I have a datastore that should save both the wins and coins of the leaderstat but it is not working and there are no errors. It doesn't print anything out or warn me. Can someone please help me understand this. Thank you
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStore")
local function onPlayerAdded(plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local wins = Instance.new("IntValue",leaderstats)
wins.Name = "Wins"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
local playerUserId = "Player_".. plr.UserId
local data
local success, errormessage = pcall(function()
data = DataStore:GetAsync(playerUserId)
end)
if success then
if data then
wins.Value = data.wins
coins.Value = data.coins
end
end
end
local function onPlayerRemoving(plr)
local playerUserId = "Player_".. plr.UserId
local data = {
wins = plr.leaderstats.Wins.Value;
coins = plr.leaderstats.Coins.Value;
}
local success,errormessage = pcall(function()
DataStore:SetAsync(playerUserId, data)
end)
if success then
print("Data successfully saved!")
else
print("There was an error")
warn(errormessage)
end
end
game.Players.PlayerAdded:Connect(onPlayerAdded)
game.Players.PlayerRemoving:Connect(onPlayerRemoving)

2 comments
How do you add the coins?
through a script not a local one