Check if a string is a valid game instance or not

I want to check if a string is a valid game instance: (for some random change part color by user inputs the path)

local path = "game.Workspace.Baseplate" -- returns true
local path = "this is not a instance" -- returns false
local path = "game.Workspace.thispartdoesntexist" -- returns false

Thanks for help!

1 Like

Using the function provided in this post, you can retrieve the information you want.

I haven’t test this out
But if the string contains invalid thing? Like examples on above

You would have to modify the function to suit your needs. For starters, try checking if there are any “.” (dots, periods) inside the string.

Ok, I will try it and give you updates, cheers!

I have gotten an update

I used a pattern check to check if the string is valid instance pattern

Script:

local pattern = 'Workspace%..'
    local pattern2 = 'game[%.]Workspace%..'
    if string.match(str, pattern) or string.match(str, pattern2) then
        print("yes")
    else
        print("nooo")
    end

Now I don’t know how to check if the path is in game or not

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.