Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

attempt to index nil with 'GetChildren' when using a tool?

heres the script

local tool = script.Parent

local lp = game.Players.LocalPlayer
local char = lp.Character

tool.RequiresHandle = false

tool.Activated:Connect(function()
	for i, v in pairs(char:GetChildren()) do
		if v:IsA("Part") then
			v.Transparency = 1
		end
	end
	
end)

it gives me this error: Players.compenseeritudalt.Backpack.Tool.LocalScript:9: attempt to index nil with 'GetChildren'

1 comment

0

When do you run this script?

2 answers

Guys i fixed it you have to put

 if not character or not character.Parent then
	character = player.CharacterAdded:wait()
end

after the local character

You could have just done

local lp = game.Players.LocalPlayer
local char = lp.Character or lp.CharacterAdded:Wait()

It makes things much easier.

This discussion is preserved as it was. New answers, comments, and votes are closed.