what is !strict i saw it in scripts but idk what it does
1 Like
Hope that helped.
Specifically: Type checking | Documentation - Roblox Creator Hub
It’s just a type checking mode that determines how the roblox debugger will handle your scripts.
2 Likes
strict allows for strict typing
like giving warnings when a wrong type is used
(There are strictly types languages and dynamically types languages Luau is dynamically typed
but using --!strict allows for strict typing in luau)
example
--!strict
local str = "Hello World!"
str = 5 -- error type number cannot be converted into string
--!strict
local str : string | number = "Hello World!"
str = 5 -- no error
you can find a lot of tutorials about it by searching
4 Likes
pretty much what the others said. It highlights typechecking issues. It can be helpful for pointing out small issues in code logic, too.
Pointing out small typos
--!strict
local label = script:WaitForChild("TextLabel") :: TextLabel
local var = script:GetAttribute("SomeAttribute_CFrame") :: CFrame
--imagine you had some text here you retrieved from somewhere else
local text = "blah blah"
--you accidentally wrote var instead of text...
label.Text = var -- Value of type 'CFrame' could not be converted into type 'string'
Typechecking
local foo = 3
print(string.find(
foo, --type 'number' could not be converted into 'string'
"hi"
))
local function foo(a: number, b: number)
--...
end
foo(3) --function 'foo' expects 2 arguments but only 1 was specified
local function bar(a: number, b: number?)
--...
end
bar(3) --no warning
there’s a bunch more examples but here’s a few
1 Like