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
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))
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.
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.
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