Team is set to neutral

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)

you have to turn on AutoAssignable on the team for the first stage so that players will start there when they join

yes, it is on, but it still creates the team of neutral

the first line in your PlayerAdded function makes them neutral lol

2 Likes

oh my god, im so dumb hahah

tysm!! <3

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.