So what I attempted to do is have a character earn currency which puts them on a different team. For example, if a player earned 100 cash they would be on a team called Club 100 and so on. I already have the currency saved but what I learned was that when a player leaves a sever and joins again, they spawn back at Club 0. How can I use datastore to save what Team the player is on?
Use DataStore
silly :
local DataStoreService = game:GetService(“DataStoreService”) local DataStore = DataStoreService(“DataStore”) -- Name this whatever you want local function loadStarterData(Player) -- Basically this is the function that creates the stats local leaderstats = Instance.new(“Folder”) leaderstats.Name = “leaderstats” leaderstats.Parent = Player local Cash = Instance.new(“IntValue”) Cash.Name = “Cash” -- Name your currency Cash.Parent = leaderstats end local function loadData(Player) -- Function that loads the data local Data local s,e pcall(function() Data = DataStore:GetAsync(“UserId:”.. Player.UserId) end) if s then Player.leaderstats.Cash.Value = Data[1] Player.Team = game.Teams[Data[1]] print(“Loaded ”.. Player.Name ..”’s data successfully”) else print(“Failed to load ”.. Player.Name ..”’s data”) end end local function saveData(Player) -- Function that saves the data local Data = { Cash = 0, Team = “” } Data.Cash = Player.leaderstats.Cash.Value Team = Player.Team.Name local s,e pcall(function() DataStore:SetAsync(“UserId:”.. Player.UserId, Data) end) if s then print(“Saved ”.. Player.Name ..”’s data successfully”) else print(“Failed to save ”.. Player.Name ..”’s data”) end end game.Players.PlayerAdded:Connect(function(Player) loadStarterData(Player) loadData(Player) end) game.Players.PlayerRemoving:Connect(function(Player) saveData(Player) end)