I’m working on a function and I ran into a typechecking issue that I’m unsure of. This error is occurring on the first line within the function:
Type 'Instance' could not be converted into 'ProximityPrompt?'
The Luau website on this says this though:
When one type inherits from another type, the type checker models this relationship and allows to cast a subclass to the parent class implicitly, so you can pass a
Part
to a function that expects anInstance
.
This quote doesn’t exactly relate to the issue here, but why can’t I define prompt
as a ProximityPrompt which inherits from Instance. Do I have to define prompt
as an Instance to get this to work? Here’s the function:
--!strict
function Prompts:InvertPromptAction(parent: Instance, action1: string, action2: string)
local prompt: ProximityPrompt? = parent:FindFirstChild(action1) or parent:FindFirstChild(action2)
if prompt then
if prompt.Name == action1 then
Prompts:ChangeAction(prompt, action2)
else
Prompts:ChangeAction(prompt, action1)
end
end
end