Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Unable to Store Instance in DataStore?

I'm trying to make a DataStore to save data, but it keeps on giving me an error saying 104: Cannot store int in data store. Data stores can only accept valid UTF-8 characters.

This is the script:

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerTeamData")

Players.PlayerAdded:Connect(function(player) 
	
	local playerName = tostring(player.Name)
	
	local key = "player-"..player.UserId
	
	local data
	
	local success, errorMessage = pcall(function()
		data = DataStore:GetAsync(key)
	end) 
		
	if success then
		if data then
			print(playerName.."'s".." data has been loaded.")
			player.Team = Teams[data]
		end
	else
		warn("Unable to load "..playerName.."'s ".."data.")
		warn(errorMessage)
	end
end)

Players.PlayerAdded:Connect(function(player) 
	
	local playerName = tostring(player.Name)
	
	local key = "player-"..player.UserId
	
	local success, errorMessage = pcall(function()
		DataStore:SetAsync(key, player.Team)
	end)
		
	if success then
		print(playerName.."'s".." data has been saved.")
	else
		warn("Unable to save "..playerName.."'s ".."data.")
		warn(errorMessage)
	end
end)



2 comments

0

What is TeamColor's classname?

0

I meant to say player.Team = Teams[data] instead of player.TeamColor*

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.