While making a script with --!strict I am starting to notice that every time I try to: :WaitForChild() an Instance, it gives me a type error annotation in my code editor that it can’t turn an Instance, to, for example, an part.
This is kinda hard to explain so here is an example script:
--!strict
local WaveLabel: Frame = script.Parent
local counter: TextLabel = WaveLabel:WaitForChild("Counter") -- TYPE ANOTAION: Type 'Instance' could not be converted into 'TextLabel'
counter.Text = "Text!"
Little Edit: This isn’t in any way critical, the code runs just fine, It’s just kinda annoying having that annotation in the editor even knowing everything is fine
There are seemingly small problems in your code snippet. The only thing you’re doing wrong is “counter: TextLabel”, using !strict, and the WaitForChild() function can’t convert it to a text label.
Also, make sure your script actually has to be strict before adding it. It may be another possible thing that causes your error.
Try this code snippet:
local WaveLabel = script.Parent
local counter = WaveLabel:WaitForChild("Counter")
counter.Text = "Text!"
As I said, using !strict may cause the issue and I believe there is no need to define a type for each variable, as you know what they are.