How do i define Animator object properly?

I am trying to define the Animator object, however it keeps on giving a warning that says “Type ‘Instance’ could not be converted into ‘Animator’”
image
I am not sure if that’s the right category, if it’s not i’m sorry

local plr: Player = game.Players.LocalPlayer
local char: Model = plr.Character or plr.CharacterAdded:Wait()

local hum: Humanoid? = char:FindFirstChildWhichIsA("Humanoid")

local animator: Animator? = hum:WaitForChild("Animator")

Why are you adding : to your variables?

LuaU typechecking is only avaliable for functions and in your case, it is simply not needed.
Try this instead:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
local Animator = Humanoid:WaitForChild("Animator")
1 Like

I was trying to get the functions and events of the Animator to display in the auto-complete too, instead of the functions inherited from Instance only

This wouldnt be possible with the current Auto-completion that we have up to date

1 Like

image
Nevermind, just made it work without the warnings (left the other variables without type declaring)

2 Likes

Huh, the more you know. I never knew this was possible.

If you mean the type checking, you can learn more here - Type checking - Luau.

1 Like