I am making a game right now and i wanna know how to save the player's team like the game "The Impossible Obby", basically i want it to saves the player's team when the player leaves and when the player reachs another spawn location (with a different team).
Just use the DataStoreService and make the team a value. Here is a whole tutorial on Save Data Keep in mind SaveData is an advanced scripting service.
Well, I'm pretty sure you can retreive a team from a name (string) and a name (string) from a team. So from the team the player is in take the name, and store it in a datastore, then when they join again later take the name of the team from the datastore and assign the player to the team with that name.
This is how I would do it.
ModuleScript in ServerScriptService and I named it "TeamModule" -
local teamModule = {} local DataStore2 = require(1936396537) DataStore2.Combine("MainKey","Team") -- You Can Change MainKey To Any New Value To Reset The DataBase local defaultTeam = "None" function teamModule:SetPlayerTeam(player) if player:IsA("Player") then local excessData = Instance.new("Folder",player) excessData.Name = "ExcessData" local teamValue = Instance.new("StringValue",excessData) teamValue.Name = "Team" local teamStore = DataStore2("Team",player) local function updateTeam(team) player.ExcessData.Team.Value = team end updateTeam(teamStore:Get(defaultTeam)) teamStore:OnUpdate(updateTeam) else error("The First Parameter Has To Be A Player") end end return teamModule
This is a ServerScript in ServerScriptService and I named it TeamSet -
local teamModule = require(script.Parent.TeamModule) local DataStore2 = require(1936396537) local RE = game:GetService("ReplicatedStorage"):WaitForChild("Events") game.Players.PlayerAdded:Connect(function(player) teamModule:SetPlayerTeam(player) wait(1) local team = game:GetService("Teams"):FindFirstChild(player.ExcessData.Team.Value).TeamColor wait() player.TeamColor = team wait(0.25) player:LoadCharacter() end) RE.TeamChange.OnServerEvent:Connect(function(player,team) player.TeamColor = game:GetService("Teams"):FindFirstChild(team).TeamColor player.ExcessData.Team.Value = team local teamStore = DataStore2("Team",player) teamStore:Set(team) wait(0.1) player:LoadCharacter() end)
And Then I have a folder in ReplicatedStorage called Events, and you should keep all RemoteEvents and Functions in there, and it will save their team. All you have to do is have the first team enabled Auto-Assignable, and the other teams should not have that enabled. It will get their team, and then respawn them on their team at that spawn. It should work, if it doesn't, let me know so I can tweak it and fix it for you.