local dss = game:GetService("DataStoreService")
local deathData = dss:GetDataStore("deathData")
local teamData = dss:GetDataStore("teamData")
game.Players.PlayerAdded:Connect(function(plr)
plr.Neutral = true
local lb = Instance.new("Folder", plr)
lb.Name = "leaderstats"
local deaths = Instance.new("IntValue", lb)
deaths.Name = "Deaths"
--deaths loading
local death
local succ, err = pcall(function()
death = deathData:GetAsync(plr.UserId.."-deaths")
end)
if succ then
deaths.Value = death
else
warn("Error with getting deaths: " ..err)
end
--stage loading
local team
local succ, err = pcall(function()
team = teamData:GetAsync(plr.UserId.."-team")
end)
if succ then
plr.Team = game.Teams:FindFirstChild(team)
else
warn("Error with getting team: " ..err)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
--deaths
local succ, err = pcall(function()
deathData:SetAsync(plr.UserId.."-deaths", plr.leaderstats.Deaths.Value)
end)
if succ then
print("Deaths successfully saved.")
else
warn("Error with saving deaths: " ..err)
end
--stage
local succ, err = pcall(function()
teamData:SetAsync(plr.UserId.."-team", plr.Team.Name)
end)
if succ then
print("Deaths successfully saved.")
else
warn("Error with saving stage: " ..err)
end
end)
im not entirely sure why its not working so maybe try defining the team that they are on as a variable at the beginning of the PlayerRemoving function and see if it works then
ok so it appears that I leave before the game can set my team to lobby.
Also whenever I join the team I am on is automatically in neutral, and not lobby or whatever team they were on. I have made sure that lobby is auto assignable, but yet it does not work