The title is pretty much it and is pretty straight forward. My scripts keep trying to assume things about my code and I do not feel like making redundant value checks for events that have almost zero chance of happening.
You can work-around it like this:
local ClickDetector = (locker.Parent::Instance):FindFirstChild("ClickDetector") :: ClickDetector
Alternatively, you can go the nuclear option and disable type analysis all together with this at the top of your script:
--!nocheck
But I don’t recommend doing that
Who knew me simply wanting to remind myself what types I have to put in my module functions would lead to this chaos lol, ty !
Another way to do this is:
local ClickDetector: ClickDetector = ...
But this is a good feature and the checks aren’t redundant and the point of these warnings is to encourage developers to create robust code that is easy to build on after the fact. You should really only ignore these warnings if you are testing something that isn’t going to be production.
Thank you, the reason why I thought it was redundant is because of the fact that the script would not have been able to run if there was no parent since that means the click detector that runs the script would not have been able to run. Your wisdom is greatly appreciated though : ) I am trying to create more reliable code more. Here’s the full script to show my progress in doing so
local Modules = game:GetService("ServerScriptService").Modules
local PlayerModifier = require(Modules.PlayerModifier)
local LH = {}
function LH.Enter(plr: Player, locker: Model)
local char = plr.Character
if not char then warn("Player does not have a character") return end
local Main = locker:FindFirstChild("Main")::BasePart
local ClickDetector = (locker.Parent::Instance):FindFirstChildWhichIsA("ClickDetector")
ClickDetector.MaxActivationDistance = 0
local humRoot = char.PrimaryPart
local Humanoid = char:FindFirstChildWhichIsA("Humanoid")
local EnterLocation = humRoot.CFrame
humRoot.CFrame = Main.CFrame * CFrame.new(0, 2.5, 0)
task.wait(0.05)
humRoot.Anchored = true
plr.CameraMode = 1
PlayerModifier.InvisibleCharacter(char, true)
print("Listening for Movement")
local connection;
connection = Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
print("Movement")
humRoot.Anchored = false
task.wait(0.05)
humRoot.CFrame = EnterLocation
plr.CameraMode = 0
PlayerModifier.InvisibleCharacter(char, false)
ClickDetector.MaxActivationDistance = 5
connection:Disconnect()
end)
end
return LH
The one-line if statements to make sure things exist always narrow things down. I use it a lot in roblox-ts and if you ever want to do more advanced things with typing you should check it out.
Why are you using FindFirstChild anyway if you’re not checking whether it’s returning nil? That defeats the purpose of FindFirstChild. If you know that the click detector will not be nil, just access it directly.
How about a way to fully disable that everywhere
It’s really annoying
Like I said it’s there for a reason. Type checking exists to make it easier for big projects and it encourages making good production code that will last.
Edit to what I said
Some heading that adds strict typing was enabled
Wasnt really happy when I found that out
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.