Attempt to concatenate string with Instance, but Instance is an Integer?

Hello,

I’m currently trying to get a player’s Username from DataStore2 using the GetData function from this post. It normally works fine with everything else, but I’m stumped here. Basically, I’m using a RemoteFunction that will grab the Username from the GetData function, but Roblox thinks I’m trying to pass an instance through UserId, but I’m actually passing an Integer through. This should be working fine, so I really have no clue what’s going on. Here’s my code:

Server Script:

function GetData(dataStoreName, UserId) -- https://devforum.roblox.com/t/datastore2-editing-players-data-if-theyre-offline/842218
	local orderedDataStore = DataStoreService:GetOrderedDataStore(dataStoreName .. "/" .. UserId)
	local dataStore = DataStoreService:GetDataStore(dataStoreName .. "/" .. UserId)

	local pages = orderedDataStore:GetSortedAsync(false, 1)
	local data = pages:GetCurrentPage()
	if data[1] ~= nil then
		return data[1]["key"], dataStore:GetAsync(data[1]["key"])
	end
end

funcs.GetPlrUsername.OnServerInvoke = function(userId)
	local PlayerKey, PlayerGameData = GetData(masterKey, userId)
	
	if PlayerKey and PlayerGameData ~= nil then
		return PlayerGameData["Username"]
	end
end

Clientside Script:

function CreateFriendTemplate(userId, headshot)
	print(tostring(userId)) -- prints a UserID
	local friendUsername = game.ReplicatedStorage:WaitForChild("Functions"):WaitForChild("GetPlrUsername"):InvokeServer(userId)
	if homePanel:WaitForChild("Friends"):WaitForChild("NoFriendsText").Visible then homePanel:WaitForChild("Friends"):WaitForChild("NoFriendsText").Visible = false end
	
	local newFriendTemplate = script:WaitForChild("FriendsTemplate"):Clone()
	newFriendTemplate.Name = "Friend_" .. tostring(userId)
	newFriendTemplate.Image = headshot
	newFriendTemplate.Parent = homePanel:WaitForChild("Friends"):WaitForChild("FriendDisplay")
	newFriendTemplate.Username.Text = friendUsername
end

for v,i in pairs(player:WaitForChild("Friends"):GetChildren()) do
	local image = game.Players:GetUserThumbnailAsync(i.Value, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size100x100)
	CreateFriendTemplate(i.Value, image)
end

Any idea why this isn’t working? I’ve been trying to figure it out for the past hour and I can’t figure the issue out.

funcs.GetPlrUsername.OnServerInvoke = function(player, userId)

2 Likes

How did I not see that, thanks.