So I was trying to save a player’s wins with DataStoreService, but even changing my wins count to 100 still prints Derpee_Kirbee's data has been saved as 0 Wins! Here is the script:
Script
local DataStoreService = game:GetService("DataStoreService")
local myDataStore = DataStoreService:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local wins = Instance.new("IntValue",leaderstats)
wins.Name = "Wins"
while wait(10) do
local success, errorMessage = pcall(function()
myDataStore:SetAsync(player.UserId, player.Name .. " " .. player.leaderstats.Wins.Value)
end)
if success then
print(player.Name .. "'s data has been saved as " .. player.leaderstats.Wins.Value .. " Wins!")
else
print(player.Name .. "'s data did not save!")
warn(errorMessage)
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local success, errorMessage = pcall(function()
myDataStore:SetAsync(player.UserId, player.Name .. " " .. player.leaderstats.Wins.Value)
end)
if success then
print(player.Name .. "'s data has been saved as " .. player.leaderstats.Wins.Value .. " Wins!")
else
print(player.Name .. "'s data did not save!")
warn(errorMessage)
end
end)