Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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

Whoops.

assetsUtils.getPlayerThumbnail(player)

should be

assetsUtils:getPlayerThumbnail(player)
Ad

Answer this question