RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"Create a team save script that saves a players team"
-- server script local DataStoreService = game:GetService("DataStoreService") local teamDataStore = DataStoreService:GetDataStore("TeamData") game.Players.PlayerAdded:Connect(function(player) local success, team = pcall(function() return teamDataStore:GetAsync(player.UserId) end) if success and team then player.Team = game.Teams:FindFirstChild(team) end end) game.Players.PlayerRemoving:Connect(function(player) local success, err = pcall(function() teamDataStore:SetAsync(player.UserId, player.Team.Name) end) if not success then warn("Failed to save team data for player " .. player.Name .. ": " .. err) end end)