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

Why isn't the :GetChildren() function not working?

if game.Workspace.Random.ONE.Value == 1 then
	local children = game.Workspace.Levels.ONE.one:GetChildren()
	for c = 1, #children do
		
	if children[c].className == "Part"
	then
	children[c].Transparency = 1
	children[c].CanCollide = false
	end
end
end

So what i'm trying to do is if random has the value of 2, then it will :GetChildren() of game.Workspace.Levels.ONE.one and make it fully transparent. When I disable the random script, and set the vaule to 1, it still doesn't work, please help. No output errors

1 comment

0

What would that do? Not to sound mean or anything.

2 answers

✓ Accepted answer

Well your first error, is the first line:

if game.Workspace.Random.ONE.Value == 1 then

This only fires once the value is one.

Another thing could be that you need to create a loop, for the script to loop.

For what you want your code should look something like this:

while true do --- For the loop
	wait(0.0001)  -- While loops run really quick, we disable that Roblox turns off the loop, because of it going to quick, with a quick wait.
	if game.Workspace.Random.ONE.Value == 2 then
		local children = game.Workspace.Levels.ONE.one:GetChildren()
		for c = 1, #children do
			if children[c].className == "Part" then
				children[c].Transparency = 1
				children[c].CanCollide = false
			end
		end
	end
end

I hope this answered your question. - Toby

Here:

coroutine.resume(coroutine.create(function()
while true do
wait(1)
for _,OBJECT in ipairs(workspace.Levels.ONE.one:GetChildren()) do
if OBJECT.className == "Part" then
OBJECT.Transparency = 1
OBJECT.CanCollide = false
end
end
end
end))

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