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

Won't get all the children in the model [Light Arrow]??

My script is suppose to set the transparency to 0 and 1 for all the parts in [light arrow] but it only does 1 random part in the model

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()

    local Switch = script.Parent.Switch
    local ConLights = script.Parent["Light Arrow"]:WaitForChild(script.Parent["Light Arrow"].LPart, 12)
    while Switch.Value == true do
        task.wait()
        for _, ConLights in ipairs(script.Parent["Light Arrow"]:GetChildren()) do 
            ConLights.Transparency = 0
            wait(1)
            ConLights.Transparency = 1

            end
        end
end)

2 comments

0

At the same time or one by one? Also you're overwriting ConLights in Line 7, maybe you're trying to edit the ConLights in Line 4

0

At the same time. on line 7 I thought that is the way to get all the parts in the model [Light Arrow]

2 answers

✓ Accepted answer

To change all parts at the same time, use a coroutine. Wrap Lines 9-11 in either coroutine.wrap() or task.spawn() (recommended).

For this I'm using @aleandroblingo's answer.

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()
	local Switch = script.Parent.Switch
	local LightArrow = script.Parent["Light Arrow"]
	
	while Switch.Value == true do
		task.wait()
		
		for _, ConLights in ipairs(LightArrow:GetChildren()) do
			task.spawn(function()
				ConLights.Transparency = 0
				task.wait(1)
				ConLights.Transparency = 1
			end)
		end
	end
end)

4 comments

0

Thx for ur help

0

Wait there is a minor bug I am getting now when I changed the wait time to 4 it doesn't wait 4 seconds it just keeps doing it every second

0

line 6 or 11? you should change line 6 not 11

0

OK THX

If I'm correct, this only returns one instance of the specified child, meaning that your ConLights variable only refers to one part in the "Light Arrow" object.

To fix this issue, try to replace the WaitForChild method with the GetChildren method, which will return a table containing all the children of the "Light Arrow" object. Then, you can iterate over this table using a for loop and apply the transparency changes to each part individually.

Try this script:

game.ReplicatedStorage["Light Settings"]["Left Lights"].OnServerEvent:Connect(function()
    local Switch = script.Parent.Switch
    local LightArrow = script.Parent["Light Arrow"]
    
    while Switch.Value == true do
        task.wait()
        
        for _, ConLights in ipairs(LightArrow:GetChildren()) do 
            ConLights.Transparency = 0
            wait(1)
            ConLights.Transparency = 1
        end
    end
end)

1 comment

0

No I am wanting it to change all the parts transparency at the same time. Mine right now does what your script does.

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