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

attempt to index a nil value ?

Asked by 9 years ago

22:03:30.531 - Players.Player1.PlayerGui.ScreenGui.Core:11: attempt to index a nil value 22:03:30.532 - Stack Begin 22:03:30.536 - Script 'Players.Player1.PlayerGui.ScreenGui.Core', Line 11 22:03:30.538 - Stack End

works in studio not play

local gui = script.Parent
local frame = gui:findFirstChild("Frame",true)
local setting = gui.Settings
local openclose = setting.OpenClose
local slide = setting.Slide
local money = setting.MoneyType
local keyd = setting.KeyDown
local button = gui:findFirstChild("Button",true)
local Player = script.Parent.Parent.Parent 
local mouse = Player:GetMouse()
local list1 = gui:findFirstChild("Frame",true):findFirstChild("Frame1",true):GetChildren()

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

Using :FindFirstChild is pointless if you're immediately going to access things on it (see line 11).

You should probably use :WaitForChild(name); this will definitely not return nil because it freezes until there actually is an object there.

1
Note that he is using FIndFirstChild to search recursively :) NotsoPenguin 705 — 9y
2
Perhaps, though I would argue that recursive FindFirstChild is almost never a good solution. BlueTaslem 18071 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Also in my experience using more than one : in a line of code, for example

workspace:FindFirstChild("yoyo").model:FindFirstChild("yoyoman").Size = Vector3.new(math.random(1,10), math.random(1,10), math.random(1,10))

would error. if you need to use more than one do it like this

yoyo = workspace:FindFirstChild("yoyo")
brick = yoyo.model:FindFirstChild("yoyoman")
brick.Size = Vector3.new(math.random(1,10), math.random(1,10), math.random(1,10))

Answer this question