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

Can't seem to get Instance:GetChildren() to work?

here is my code:

--wait(10)
--workspace["Nuclear alert"]:Play()
--wait(101)
workspace["Nuclear Alarm Siren"]:Play()
--wait(20)

local nC = workspace.NukeCloud:GetChildren()
nC.Transparency = 0.25

while workspace.NukeCloud.PrimaryPart.Position.Y < 3.301 do
	workspace.NukeCloud:SetPrimaryPartCFrame(workspace.NukeCloud.PrimaryPart.CFrame + Vector3.new(0,0.1,0))
	wait()
end

wait(5)


The transparency change doesn't go through... What am i doing wrong?

1 answer

Instance:GetChildren does not return a dictionary, but a table. It would look something like this:

local Children = {game.Workspace.Part1, game.Workspace.Part2}

So to find a specific child you have to itterate through the table

local children = game.Worksapce.Folder:GetChildren()

for index, object in pairs(children) do
	if part.Name == "Part Name Here" then
		-- code for the part
		part.Transparency = 0.5
	end
end


-- for general

for index, object in pairs(children) do
	if object.ClassName == "Part" then --- Check if it is a part 
		object.Transparency = 0.5
	end
end

I hope this helps :)

2 comments

0

oh, so how would i do it for every children? like a general thing?

0

I edited the code :)

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