DataStore not properly saving TeamColor

Hey guys,

I’m trying to save a player’s TeamColor to a DataStore so that when they rejoin, they are on the same team, however, I keep getting an error.

12:11:16.226 104: Cannot store int in data store. Data stores can only accept valid UTF-8 characters. - Server - TeamSave:17

Here is my code, could the issue be the space in the TeamColor? If you all could help me out, that would be greatly appreciated.

Here is my code BTW, and I know I’m not using pcall, it really doesn’t make a difference to me.

local DataStoreService = game:GetService("DataStoreService")
local LevelSaves = DataStoreService:GetDataStore("Levels")
local Teams = game:GetService("Teams")

game.Players.PlayerAdded:Connect(function(plr)
	local TeamColor = LevelSaves:GetAsync("TeamColor"..plr.UserId)
	if TeamColor == nil then
		plr.TeamColor = BrickColor.new("White")
		print(tostring(TeamColor))
	else
		plr.TeamColor = BrickColor.new(tostring(TeamColor))
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local TeamToSave = plr.TeamColor
	LevelSaves:SetAsync("TeamColor"..plr.UserId, TeamToSave)
end)

Thanks!

What type is the TeamColor, I don’t think that DSS can save stuff like Brickcolor or Color3, I would suggest save the BrickColor Name.

try doing

game.Players.PlayerRemoving:Connect(function(plr)
	local TeamToSave = tostring(plr.TeamColor)
	LevelSaves:SetAsync("TeamColor"..plr.UserId, TeamToSave)
end)
2 Likes

Well now I don’t get the error, but it’s saving nil to the DS. My print statement in the code is printing nil to the output.

Nevermind! It was cause I was still in the game. Thanks! That fixed it!

Well, It’s weird, it works when it wants to.

Nvm fixed it!

1 Like