Is it possible to signify optional arguments in your own functions?

Hello! This isn’t incredibly important but, it would be really neat to know if this is doable.
I have already tried looking up keywords on here and haven’t able to find anything.

I want to know if it’s possible to indicate that an argument is optional when creating your own function.

Here’s an example of it being done in a built in method/function (not sure what’s the proper terming haha)

I’m completely aware you can make optional arguments, that’s not what I’m looking for. I just want to know if you can signify that it’s optional with the question mark seen above.

NEVERMIND!!! Immediately after posting this, I realized you can use the same type checking as always and just include a “?” after.

For any future people with this problem, here’s an example as to how you can do it:

function kill(plr: Player,delayTime: number?)
	delayTime = delayTime or 0
	task.wait(delayTime)
	plr.Character.Humanoid.Health = 0
end

with this example, it’ll look like this:
image

2 Likes

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