Hi, im making an obby game and it saves what team you were on.
However this doesn’t work as whenever you join you are automatically set to the team of ‘Neutral’
I have no idea why this is happening. Can anybody help??
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)