Not all codepaths return 'string' in editor

  1. What do you want to achieve? Keep it simple and clear!
    I want to make it so my function can recieve string and nil, but not in a table.
  2. What is the issue? Include screenshots / videos if possible!
    Not all codepaths return ‘string’ in the editor.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have tried (string,nil) and (string ? nil).

Here’s my full code:

local Players = game:GetService("Players")
local rs = game:GetService("RunService")

local module = {}
function module:GetAvatar(userId:number,thumbType:Enum.ThumbnailType,thumbSize:Enum.ThumbnailSize): (string)
	if userId then
		local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		if isReady then
			return tostring(content)
		end
	else
		if rs:IsClient() then
			local content, isReady = Players:GetUserThumbnailAsync(game.Players.LocalPlayer.UserId, thumbType, thumbSize)
			if isReady then
				return tostring(content)
			end
		end
	end
end
return module

Just add return "" at the end of the function:

function module:GetAvatar(userId:number,thumbType:Enum.ThumbnailType,thumbSize:Enum.ThumbnailSize): (string)
	if userId then
		local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
		if isReady then
			return tostring(content)
		end
	else
		if rs:IsClient() then
			local content, isReady = Players:GetUserThumbnailAsync(game.Players.LocalPlayer.UserId, thumbType, thumbSize)
			if isReady then
				return tostring(content)
			end
		end
	end

    return "" -- If nothing else is returned, just return a blank string
end
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.