So I just wanted to ask if there is some way (other than using typed Luau) to avoid these long and hard-to-read if checks when having to check the type of a specific data passed by the client.
1 Like
You can just split them apart using enter key
The if line can be spread into multiple lines, like ItsMeFelixAccept said.
Got messaged by a friend saying that there is no way to actually shorten these checks other than splitting them apart using enter keys as ItsMeFelixAccept said, guess I’ll have to keep writing those long checks.
A lot of the length comes from you repeating yourself, store Flashligh.Model
in a variable.
local model = (Flashlight and Flashlight.Model)
if (typeof(model) == "Instance") and model:IsA("BasePart") and (typeof(newCFrame) == "CFrame") then
end
Assuming you can just exit if the data is invalid, you can write it more like this:
local model = (Flashlight and Flashlight.Model)
if (typeof(model) ~= "Instance") or (not model:IsA("BasePart")) then
return
end
if typeof(newCFrame) ~= "CFrame" then
return
end
Splits up the check for each parameter, not the worst thing.
2 Likes