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

How can I prevent this from happening?

Asked by 10 years ago

I have a script that needs to get data from a model in ServerStorage but it keeps giving me this error: attempt to index a nil value

The script line is this:

for i,v in pairs(game:GetService("ServerStorage"):FindFirstChild("Data"):GetChildren) do

Then it gets the data from it but sometimes it has nothing in it and it checks it any way returning a nil value and therefore returns an error. Do YOU know how to fix this?

1
You forgot the '()''s for the 'GetChildren' method. TheeDeathCaster 2368 — 10y

1 answer

Log in to vote
0
Answered by
DeadToMe 105
10 years ago

"GetChildren" is a method, and thereby needs parenthesis at the end of it. The correct line is as followed.

for i,v in pairs(game:GetService("ServerStorage"):FindFirstChild("Data"):GetChildren()) do

Please remember to vote as an act of kindness. It does help.

Ad

Answer this question