So Basically, when you touch the part, you get a "Win" but when you reconnect, it doesn't save.
local debounce = false
local dataStoreService = game:GetService("DataStoreService")
local statStore = dataStoreService:GetDataStore("StatStore")
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local wins = Instance.new("IntValue",leaderstats)
wins.Name = "wins"
wins.Value = 0
local recieved, notRecieved = pcall(function()
stat = statStore:GetAsync("UserId-"..player.UserId)
end)
workspace.WinPart.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if hit.Parent.Humanoid.Health > 0 then
if debounce == false then
debounce = true
-- PLAYER TELEPORTS/wins
wins.Value = wins.Value + 1
hit.Parent.HumanoidRootPart.CFrame = CFrame.new(234, 45.906, -114)
end
else
print("You Lose")
end
wait(1)
debounce = false
end
end)
if recieved then
wins.Value = stat
print("Stat was recieved")
else
print("Stat was not recieved")
end
while wait(60) do
statStore:SetAsync("UserId-"..player.UserId,{wins.Value,})
print("Stat was auto saved!")
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local leaderstats = player.leaderstats
local wins = leaderstats.wins
local saved, notSaved = pcall(function()
statStore:SetAsync("UserId-"..player.UserId,{wins.Value})
end)
if saved then
print("Stat was saved")
else
print("Stat was not saved")
end
end)

1 comment
You are saving a table and attempting to read add 1 to a table.