Typchecking Problem

So as you read by the title I have a problem with typechecking.

So here’s a basic type check script:

--!strict
local t: boolean 
t = 5

The number 5 is underlined in yellow because it’s not a boolean value, but that doesn’t show any error in the in the output. Is it not supposed to give a error or am I doing something wrong? If it’s not supposed to give a error, then what exactly can type checking be used for?

It doesn’t give an error because technically it’s acceptable in lua, typechecking will only underline things in yellow to assist you in making sure you are passing the right type.

Oh. I see, then here’s a follow up question:

People use type checking in remote events(for parameters), but since type checking doesn’t effect the script at all, how is type checking helpful in the remote event parameters

example:

RemoteEvent.OnServerEvent:Connect(function(Player, variable: string) 

print(variable)

--how is checking if variable is a string helpful if it doesn't stop the script?

end)

It’s only there to assist you within your code

so if you do

re.OnServerEvent:Connect(function(player, var:string)
    -- anytime you use "var" in here it will be typechecked

    var() -- can't call type "string"
end)

Here read this post

1 Like