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