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

How Do I Fix This? "attempt to index nil with 'FindFirstChild'"

Asked by 3 years ago

so ive been getting an error saying: (Ignore The Brackets) (attempt to index nil with 'FindFirstChild')

the full error:

(17:11:57.662 - Players.Rgboffical_yt.PlayerGui.ScreenGui.Frame.Blue.LocalScript:2: attempt to index nil with 'FindFirstChild')

the portion of the code:

local tools = game.ServerStorage:findFirstChild("DataStoreFolder")
local SpeedCoil = tools:FindFirstChild("Ak-47")
print("Done!!!!!!!!!!!")

so how do i fix it please help!!! ThankYou!!!

0
FindFirstChild. not findFirstChild. f/F tracer_r 19 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Okay, so just by the error message I can see that this is a Local Script. The reason why this doesn't work is because ServerStorage can only be accessed by the Server, same goes with ServerScriptService. Local Scripts are client-sided and therefore cannot access ServerStorage. Local Scripts can access ReplicatedStorage though, so you could move the folder there instead.

0
Ok I Will Try It Tomorrow ThankYouSoMuch! Rgboffical_yt 40 — 3y
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Most likely because "DataStoreFolder" doesn't exist whenlocal tools = game.ServerStorage:findFirstChild("DataStoreFolder") ran, so tools would be nil

Try using WaitForChild instead

local tools = game.ServerStorage:WaitForChild("DataStoreFolder")
0
The issue is he's trying to get the folder from ServerStorage with a Local Script, which obviously won't work because Local Scripts cannot access ServerStorage. xInfinityBear 1777 — 3y
0
True I Am Using A LocalScript Rgboffical_yt 40 — 3y
0
Even if FindFirstChild did return nil, it wouldn't error. xInfinityBear 1777 — 3y
0
If i try WaitForChild It Just Gives Me "infiniteyield" thing Rgboffical_yt 40 — 3y
View all comments (7 more)
0
@Rgbofficial_yt Did you read the answer I posted? Try changing the location of the folder to ReplicatedStorage since local scripts cannot access ServerStorage. xInfinityBear 1777 — 3y
0
Yea tnx dude Rgboffical_yt 40 — 3y
0
DUDE TYSM Rgboffical_yt 40 — 3y
0
Np. xInfinityBear 1777 — 3y
0
Yea true i searched and i saw the article about serverstorage and ronlox said "ServerStorage Cannot Be Accesed Through Local Script/s" I Will Try Putting It To Replicated Storage tommorow cuz uhhh yea "Bed" Rgboffical_yt 40 — 3y
0
@Rgbofficial_yt i literally told you to not use ServerStorage with a LocalScript on another post.. which you also responded to. Azure_Kite 885 — 3y
0
Im sorry dude.Really Sorry Really Really Sorry Rgboffical_yt 40 — 3y

Answer this question