How to replicate the options that show with Instance.new's first parameter

For example

image

You see how all these options show up? How could I do this with a function such as

function foo(bar : baz)
    -- ...
end

foo("p") -- Part, Player, Pose, etc.

Could I also do this with a table? Like

local foo : bar = {...} 

foo.d -- Decal, Dialog, Dragger, etc.

Any help will be appreciated

3 Likes

I’m not completely sure what you’re asking for but type checking should be the way to go.

3 Likes

What I’m asking is that I want to make it so that when you try and access the index of a table it will show all the instances that shows up in the first parameter of Instance.new

Here is a photoshopped image of what I want to happen

image

1 Like

Is this for a command bar system or something similiar for clients?

Or do you just want this to be used in your scripts when you’re coding?

2 Likes

In my scripts

3030303030 chars

Yeah, so I think you need to type check. That way you get the auto writer thing.

Also, if you wanna take the easy way there’s apparently a studio code editor module that actually type checks everything for you automatically so it will always show you the auto writer thing.

I think it was called VSC?

1 Like

No I wanna do it with typechecking

Well alright then, do you know how to?

1 Like


No

I think the docs will help: Type Checking | Documentation - Roblox Creator Hub

1 Like

‮‭‮‭‮‭‮‭‮‭‮‭‮‭‭‮‭‮‭‮‭Ok thanks

If it’s what you wanted I think you should mark it as a solution for other people.

1 Like

I can’t really find what I wanted

There is nothing that tells me how to do this

Simply, sometimes roblox’s auto type writer does not occur because roblox does not know what type you are writing.

Type checking solves this since roblox will know what type you are accessing.

I can provide some code in a second.

1 Like

It’s been 3 hours lol But thanks for the help

You can’t 100% replicate the menu because that behavior is builtin. The closest you can get to that is:


Although, if you really needed to, you can do this:

local create: typeof(Instance.new) = function(class)
  -- ...
end

create( --> this will give you a list of class options like in the screenshot

But you cannot customize the behavior beyond what the engine has defined for it

1 Like

string.find would be the one.

30limitcharcharchar

1 Like

oh boy you’re gonna have fun learning what magic types are.

The short answer is, unless you want to statically generate a string union with 500 different strings, its not possible, though if you want to bully yourself, the syntax for this is:

type StringUnion = "cat" | "dog" | "fox"

function makeAnimal(animalType: StringUnion)

end
1 Like

‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭‮‭What

man-praying-black-man-praying