Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why can't I access this in the folder?

Asked by 4 years ago
Edited 4 years ago

So I have a folder "Character" which stores a folder called Class

This Folder Stores:

  • Other Folders
  • A string value that's called "CharacterClassName"

It's very strange that I get the error below too, because when I do a print statement above the line where I get the error, it prints it perfectly. The print statement is:

print(CharacterFolder.Class.CharacterClassName.Value) print(CharacterFolder.Class.CharacterClassName.Name)

So for some reason I am getting this error:

02:23:44.107 - CharacterClassName is not a valid member of Folder

When I write this block of code:

        -- Creates Character Folder
        local function CreateNewCharacterFolder(player, ChosenClass)
            local CharacterFolder = game.ServerStorage.Character:Clone()
            CharacterFolder.Parent = player.PlayerDataFolder
            CharacterFolder.Name = "Character "..CharacterNumberPresent
            -- The lines where I get the error are below
            CharacterFolder.Class.CharacterClassName.Name = ChosenClass
            CharacterFolder.Class.CharacterClassName.Value = ChosenClass
        end

1 answer

Log in to vote
0
Answered by 4 years ago

Do :WaitForChild("") On each of them, because the script might load before the objects load. Or do wait(1) in the start of the script, but the first option is better (script will work faster)

0
Read the wiki page for :WaitForChild() if you don't understand what it is. sahar1213 72 — 4y
0
Oh I’ll try that tomorrow when I wake up. I always forget about Waiting sometimes. Hopefully it works. SethHeinzman 284 — 4y
0
Yeah it makes sense too since print statements are read after the code is read through. SethHeinzman 284 — 4y
0
Arbritrary waits are never the solution. It simply hides the problem instead of fixing the solution and may not actually fix the solution hiimgoodpack 2009 — 4y
0
This was the right solution for this scenario, only because I cloned the values right before I tried to access them. SethHeinzman 284 — 4y
Ad

Answer this question