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

Calling module script function when PlayerAdded is triggered, but parameter is nil?

I'm facing an issue where in a server script I am executing this code:

local assetsUtils = require(game.ServerStorage.Utils.AssetsManager)

local Players = game:GetService("Players")

-- When a player joins, fetch thumbnail.

Players.PlayerAdded:Connect(function(player)
	
	assetsUtils.getPlayerThumbnail(player)
	
end)

I have a module script named AssetsManager with the following function inside:

local AssetsManager = {}

function AssetsManager:getPlayerThumbnail(player)
	
	print(player)
	
	-- Get Player Thumbnail
	local userId = player.UserId
	local thumbType = Enum.ThumbnailType.HeadShot
	local thumbSize = Enum.ThumbnailSize.Size150x150

	local content = player:GetUserThumbnailAsync(userId, thumbType, thumbSize)

	-- Set Image Label to Thumbnail

	local playerThumbnail = Instance.new("ImageLabel")
	playerThumbnail.Name = userId
	playerThumbnail.Parent = game.ReplicatedStorage.PlayerThumbnails
	
	print("Thumbnail for " .. userId .. "fetched.")

end

return AssetsManager

When I run the server script and print the value of player it is nil despite me passing the player parameter to the function. Does anyone know why this is happening and what I could do to fix it?

Thank you!

1 answer

The issue was I used a '.' instead of a ":"

Whoops.

assetsUtils.getPlayerThumbnail(player)

should be

assetsUtils:getPlayerThumbnail(player)

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