Problem with :GetAttribute() function

So I have a little problem with the :GetAttribute() function

I’m trying to get attribute of a specific instance using the :GetChildren() (I think a script is better than my explanation lol):

local wsassets = ws:GetChildren()
local LevelsFolder = script.Parent.Level --It's a folder.. ok it's writted on the variable

--The main script
for i,wspace in pairs(wsassets) do
	if wspace.Name == "Map" then
		local level = wspace:WaitForChild("Map")
		level.Parent = LevelsFolder[level:GetAttribute("Level")]
	end
end

But the error is :

attempt to call missing method ‘GetAttribute’ of table

1) I don’t really know what this error means

2) When I try to fix this problem, it just pops out again

I appreciate it if you try to help me :slight_smile:

2 Likes

The error states that you are trying to use :GetAttribute() on a table, which does not work.
Are you sure the level variable is an instance? You can check if you add the following line:

local level = wspace:WaitForChild("Map")
print(type(level))

I just did the script but there is an infinite yield

edit : nevermind I just found the problem of the infinite yield thing

edit2 : I redid the script and the type is an… userdata?
image

userdata is a type that represents instances of Roblox objects. so it is indeed an instance. The error likely indicates that the attribute you’re trying to access doesn’t exist. Try checking if the attribute exists.

well actually i managed to fixed it

BUT

A NEW PROBLEM JUST APPEARED

when executing this script :

local levelfold = LevelsFolder[f]

there is a new error :
attempt to index string with 'Parent'

You are trying to access a parent from a string. Obviously, strings don’t have a Parent property.

The error is likely occurring because LevelsFolder[f] is returning a string, not a table or an instance. You should ensure that LevelsFolder[f] is an instance before trying to access its ‘Parent’ property.

yeah but the thing i wanna do is get the level name and then set it’s parent to the name of the level name

If I understood correctly, you want to set the parent of the level to be a folder with the same name as the level’s attribute “Level”.

Here is how you can do it:

local wsassets = ws:GetChildren()
local LevelsFolder = script.Parent.Level

--The main script
for i,wspace in pairs(wsassets) do
    if wspace.Name == "Map" then
        local level = wspace:WaitForChild("Map")
        if level and level:IsA('Instance') then
            local levelName = level:GetAttribute("Level")
            local levelfold = LevelsFolder:FindFirstChild(levelName)
            if levelfold then
                level.Parent = levelfold
            end
        end
    end
end

one image is better than words :
image

It means there is no instance called “Map” inside of “Map”.
What you probably intended to do is local level = wspace.

Unless there’s a Map inside a Map, then that means it’s missing.

welp I guess it’s fixed

thank you man :slight_smile:

1 Like

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