Hello.
I wish to begin using strict type checking as default in my future scripts.
I am having difficult with a particular nuance of strict type checking mode.
Consider the following:
--!strict
local function target(turret: Model, target: Vector3?)
local base = turret.base
local baseHinge = base.hinge
local barrelsHinge = turret.barrels.hinge
if target then
local offsetCFrame = CFrame.new(base.Position, players[target].Character.HumanoidRootPart.Position).LookVector
I am receiving an error on on line 3 and 6 of this particular script when attempting to reference child instances ābaseā and ābarrelsā, with the error message āKey āBase/Barrelsā not found in class āModelāā.
Whilst Iām aware that :FindFirstChild() is better practice, my understanding is that there is performance overhead associated with the function and itās a lot less concise, so I donāt use it. But, in order to fix this issue, I tried to use it.
--!strict
local function target(turret: Model, target: Vector3?)
local base = turret:FindFirstChild("base")
local baseHinge = base:FindFirstChild("hinge")
local barrelsHinge = turret:FindFirstChild("barrels"):FindFirstChild("hinge")
if target then
local offsetCFrame = CFrame.new(base.Position, players[target].Character.HumanoidRootPart.Position).LookVector
However, in this case the last line gives an error stating āKey āPositionā not found in class āModelāā.
I also tried to force the type of base to be BasePart but this throws an error as well, stating that āType āInstanceā could not be converted into āBasePartāā.
I would greatly appreciate if someone could help diagnose this issue and point out what Iām doing wrong.
Thanks.
Iām aware the last line has another error associated with it, but Iām going to fix that soon, after this code works.