My issue is that I I cannot call a function on a Luau type which has a nil union type added to the type definition.
Specificaly, I cannot call the FireServer function on a type defined as local REGameItems : RemoteEvent | nil = … since the " | nil" union part makes this an “nullable”/"?" type.
When I then try to call REGameItems:FireServer(…) it gives this warning:
W000: (209,17) Type ‘RemoteEvent?’ does not have key ‘FireServer’
I cannot remove the “| nil” from the type definition since I check if this event is nil.
How can keep the “| nil” in the type definition and also not get that “Type ‘RemoteEvent?’ does not have key ‘FireServer’” warning?
I know of one way around this, but it’s very ugly, which is to use the :: operator, but I cannot get it to work without adding an extra temporary variable because I get an error otherwise:
local x : RemoteEvent = REGameItems :: RemoteEvent
x:FireServer(GameItemRemotes.REMsg_BuyItem, RemoteDataPacket)