Team not saving after disconnection

Hi, i use this for add a Player in specific team:

script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Deep orange”)

My problem: When i disconnect, my team not saving, im neutral after reconexion :confused: you know a script for save the team of player and auto-assign when he connect to server ?

Thank you

You could use Datastores for that: Data Stores | Documentation - Roblox Creator Hub

I have try it but it’s so complicated :confused:

Hello, Thorngard Please avoid the use of excessive Parents as well you can uncheck the auto assignable property. Its Under data.

This thread might help you to save teams.

don’t help me ^^ all script is broken and don’t work… i just want a script similar to:

OnplayerJoin:

If class.Value == 1 then
script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Deep orange”)
end

But i don’t have the correct words… im new in scripts :confused:

I found this script in the toolbox and made some changes. Make sure to publish your game or enable studio api before testing. Also, assign team from the server instead of doing this.

local datastore = game:GetService("DataStoreService")
local teamsave = datastore:GetDataStore("team")

-- load player team
game.Players.PlayerAdded:Connect(function(plr)
	local t
	local success, e = pcall(function()
		t = teamsave:GetAsync(plr.UserId)
	end)
	if not success then
		print("No previous data or error getting data!")
	else
		if t ~= nil then
		plr.TeamColor = BrickColor.new(t)
		plr:LoadCharacter()
		end
	end
end)



function save(plr)
	pcall(function()
	teamsave:SetAsync(plr.UserId, plr.TeamColor.Name)
	end)
end

--save when leaving
game.Players.PlayerRemoving:Connect(function(plr)
	save(plr)
end)
--autosave
while wait(300) do
	for i,v in pairs(game.Players:GetPlayers())do
	save(v)
	end
end

Thanks for your help but it’s not work :confused: i have this in a localscript:

script.Parent.MouseButton1Click:connect(function()

script.Parent.Parent.Parent.Parent.Parent.TeamColor = BrickColor.new(“Deep orange”)

script.Parent.Parent:Destroy()

end)

When i click on the button i was moved into the correct team, but if i disconnect and reconnect im neutral :frowning:

When changing team you must use ‘script’ not localscript. Or change it from the server. You can also use remoteEvent.

i have try it but only localscript can move me in team… i have testing all but in script i wasn’t move… :confused:

edit: i have move your script into serverscriptservice and it’s working… im bad lol thank you