Strange error,, The folder is nil, even though it exists

bug

I sometimes get an error when playing on the server (about 6 out of 10 times). However, I never get this error when using Roblox Studio (0 out of 10 times). I don’t know what is causing this error.

it’s so weird the object literally exists in the player character, I assign it to starterplayercharacter , and you can see it on the screenshot, the Data folder exists, I even use injector and open explorer to make sure the folder is exist

Without seeing your script, my best advice is to use WaitForChild since one script may run before it is created.

3 Likes

I apologize for not providing a script, it’s a simple script that read variable data, since I initialize the variable on startercharacter I don’t think I should provide the script, but if you want to know the script here is the script that I use to read the variable

local character = player.Character or player.CharacterAdded:Wait()
repeat
	task.wait(0.6666)
until character ~= nil
local mousebool = character.Data.Mouse

after I modify it to

local mousebool = character:WaitForChild("Data").Mouse

I got error

attempt to index nil with WaitForChild

the thing that keeps bothering me is this error sometimes appear sometimes gone when on actual server

Instead of putting the data folder in StarterCharacter, try putting it in ServerStorage and make a server script where it replicates the data folder onto the player when CharacterAdded fires like so:

local ServerStorage = game:GetService("ServerStorage")
local Players = game:GetService("Players")
local Data = ServerStorage:WaitForChild("Data")

Players.PlayerAdded:Connect(function(Plr)
    Plr.CharacterAdded:Connect(function(Char)
        local DataClone = Data:Clone()
        DataClone.Parent = Char
    end)
end) 
2 Likes

Can I ask why you’re placing your Data inside the character and not the player instance itself?

2 Likes

You should wait until it loads, a simple way of doing this

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local folder = char:WaitForChild("Folder")
2 Likes

correct, I just check that the error comes from another script that has the same name,

I didn’t realize that I have fix this code
local mousebool = character:WaitForChild(“Data”).Mouse

I initially thought that the error was still coming from the first script, but I later realized that it was actually caused by this code.

local somevalue = character.Stats.Data.somevalue

On a real server, it seems to take longer to load the child inside the startercharacter compared to on Roblox Studio, I fix it by using WaitForChild for both Stats and folder

what is the difference between putting the object on starter character and cloning? on CharacterAdded? does it make it faster to load?

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