I'm trying to save the TeamColor of a Player when he leaves the game, but the Script isn't working, and I don't know the reason.

Script:

local DataService = game:GetService("DataStoreService")
local TeamData = DataService:GetDataStore("TeamStore")

game.Players.PlayerAdded:Connect(function(Plr)
	local t = TeamData:GetAsync(Plr.UserId)
	Plr.TeamColor = BrickColor.new(t)
end)

game.Players.PlayerRemoving:Connect(function(Plr)
	local TeamColor = tostring(Plr.TeamColor)
	
	TeamData:SetAsync(Plr.UserId, TeamColor)
end)

7 comments

0

You can't save UserData, you have to save it as a string or value or table. So save the name of the team color or team and load it by setting the player's team to that saved team, or to the brick colored team.

0

Are there any errors?

0

that's why he's using tostring

0

Try adding a print after you get the player data and see if it prints nil or the value you want

0

It's printing the Value that I want

0

The TeamColor change in the Player properties, but not in the Leaderboard

0

Maybe remove the BrickColor.new()?