Orange Error Lines Under Code For No Reason

I am working on code, and using the Type system for easier autocompleting; however, whenever I use it in a ModuleScript, it shows up with orange lines under the whole thing. For example: Type 'Instance' cannot be converted into 'TextButton'. My code functions, but these orange lines make it hard to actually focus on working on the code.

Image Of Example:

I have no idea how to fix this, and I have looked at other devlogs, and they only seem to help with an actual error in code, but there is no real errors inside of my code. Please help!

ALSO: Deleting the typing is not an actual solution, that would just get rid of it this one time, instead of solving the actual issue!

Put your mouse on the red line to see what it says for an error, if there is any.

It just sounds like theres type incompatibility. Thats what the type system is for, preventing that.

hey i think i might know what’s going on with your code :slight_smile:

roblox studio sometimes shows these orange lines when it thinks there’s a type mismatch based on the type annotations you’ve used. since your code is working fine, probably it’s that the type inference is getting confused

one thing you can try is to make sure that your type annotations are as specific as possible. for example, if you have a function that’s supposed to return a ‘TextButton’, but you’ve annotated it to return ‘Instance’, studio might not realize that ‘TextButton’ is actually a more specific type of ‘Instance’

if you update your annotations to be more specific, those orange lines might go away. here’s a quick example of what i mean:

-- before
local function getButton(): Instance
    -- code here
end

-- after
local function getButton(): TextButton
    -- code here again
end

How would it be a type incompatibility, I am using a for loop, anything inside of a for loop could find almost any type of thing, whether textbutton, or anything.

I’m using a module script, and there is nothing being returned, except the function.

You are defining the type for whatever is in the for loop to be a TextButton, but you are probably getting children that arent TextButtons, so its freaking out.

image

The result of GetChildren() is ambiguous, which is probably how the code editor knows its a bad idea.

1 Like