Title says it all.
The code below is located in my custom service and is meant to retrieve (either by finding or creating) a folder inside of a player.
I simply want the function to return a type of Folder or a type of Folder? depending on the parameter/ variable named “createIfNotFound” (boolean).
It is my understanding that lua does not have explicit function overloading like most other programming languages, but I would at least like to implement a workaround so that strict mode isn’t screaming at me when I use this function within my codebase.
I am new to strict typing, so any help is appreciated. Thanks
function EconomyService.getPlayerFolder(player: Player, folderName: playerFolderId, createIfNotFound: boolean?)
local playerFolder = player:FindFirstChild(folderName) :: Folder?
if type(createIfNotFound) == "boolean" then
if createIfNotFound then
if not playerFolder then
playerFolder = Instance.new("Folder")
playerFolder.Name = PLAYER_LEADERSTATS_FOLDER_NAME
playerFolder.Parent = player
return playerFolder
end
end
end
return playerFolder
end