Loop in function does not play?

So I have a button with a serverscript that fires an event to the client. The desired output is some flashing lights and a sound. Although the sound does play and stop when the alarmon variable is off and on respectively, the lights do not flicker. Any feedback would be appreciated.
(This is inside a local script):

local event = game.ReplicatedStorage.SystemEvents:WaitForChild("Evacuation")
    local sound = workspace.SystemSounds:WaitForChild("Evacuation")
    local alarmon = false
    local debounce = false
    function Evacuate()
    if not debounce then
    	debounce = true
    		if alarmon == false then
    				alarmon = true
    				sound.Looped = true
    			sound:Play()
    		while alarmon do
    			for i, child in pairs(workspace:GetChildren()) do
    		if child.Name == "RedBeacon" then
    			child.Light.PointLight.Brightness = 1
    			wait(1)
    			child.Light.PointLight.Brightness = 0
    			wait(1)
    		if alarmon == false then
    			print("turnoff")
    			break
    		end
    		end
    		end
    		wait(1)
    		debounce = false
    		end
    		else
    			for i, child in pairs(workspace:GetChildren()) do
    			if child.Name == "RedBeacon" then
    			child.Light.PointLight.Brightness = 0
    			sound.Looped = false
    			sound:Stop()
    			wait(1)
    			alarmon = false
    			debounce = false
    			end
    			end
    		end
    	end
    	
    end

    event.OnClientEvent:Connect(Evacuate)

Local scripts can only change things for the client, maybe you can try changing the lights from the server script. And have you done :FireAllClients()? Do all of the players hear the sound?

Yeah, I am using :FireAllClients() from a serverscript. The sound does play for the players.

Can you try chaging the lights from the server script?

Well the lights can be changed from a localscript, that’s not the issue. It’s something in my formatting. (I am purposefully changing the lights from the client).

Okay, let me look more at the script for a second.

Is there anything in the output? I tested and it works for me, is there a folder/model called Light inside the part? Because you wrote child.Light.PointLight.
I made a simple script that fires the event to all clients, and I removed that Light from Light.PointLight and it worked fine, I saw it flickering
I have just put a PointLight inside the part.

1 Like

RedBeacon is a model in the workspace. Light is a part.

Are you sure you didn’t spell it wrong? It still works for me, ill send a video of it working:

1 Like

Solved it, I created a a variable (light = child.light) and then accessed it from there (light.PointLight)

1 Like

Great! But I don’t fully understand how it fixed it, Have you spelled it wrong? It worked for me without the variable. Maybe it’s because you have changed it from Light to light? I can confirm that your script worked for me without the variable and I can send a video of it

I’m not gonna lie I’m not quite sure… it’s something I noticed early on when I started scripting, at times you can’t really change a variable if it is like the child of a child of a child or something…

robloxapp-20200417-1226399.wmv (2.7 MB)

It works for me with your normal script, look at this video I made, I connected te script with a touch event, and when you touch it, it fires the event, and it works perfectly, the light is flickering and you can hear the quiet alarm.