I created a script that stores a players wins when they leave the game, and gets their wins when they join, but it always errors.
datastore = game:GetService("DataStoreService")
WV = datastore:GetDataStore("WinsValue")
game.Players.PlayerAdded:Connect(function(player)
local folder = Instance.new("Folder")
folder.Parent = player
folder.Name = "leaderstats"
local wins = Instance.new("IntValue")
wins.Parent = folder
wins.Name = "Wins"
----------------------------
local winsvalue
local suc,err = pcall(function()
winsvalue = WV:GetAsync(player.UserId)
end)
if suc then
wins.Value = winsvalue
else
print("There was an error while trying to get data")
end
end)
--------------------------------------------------------------------------------------------------------------------------------------------------------
game.Players.PlayerRemoving:Connect(function(player)
local suc,err = pcall(function()
WV:SetAsync(player.UserId,player.leaderstats.Wins.Value)
end)
if suc then
print("Successfully stored data")
end
if err then
print("There was an error while trying to store data")
end
end)
