Flickering lights

Yes! Try that. If that doesn’t work, I can send a file where it does work, and you can try it in your game and see if that fixes anything.

Wow, now it gives me infinite yield…

That’s really weird. It detects the child, then fails to index it. I’ve never seen this happen before.

Try this:
Flicker.rbxl (39.7 KB)

1 Like

Sorry for late response…

But your parts seem to be unchanging.

I’ve hit play and nothing happens.

And also there is a problem, as I’ve said in the beginning i want them to constantly loop for ever and change the brightness, but it only changes once.

Figured it out, I’ve modified the script in the way I wanted and this is the final product.

task.wait(1)

for _, light in script.Parent:GetChildren() do
	print("Reaching loop")
	task.spawn(function()
		if light:IsA("Part") then
			while true do
				task.wait(0.2)
				light.SpotLight.Brightness = 0
				task.wait(0.2)
				light.SpotLight.Brightness = 5
				print("Ended")
			end
		end
	end)
end

The only that remains is to implement it in the game.

1 Like

The reason it wasnt working is you was getting the parent of “Model” and you didnt add something like " if light:IsA(“Part”) then" so it would also check the Script for a SpotLight

I tested it myself, and it worked. That’s extremely odd.

I told them earlier that this would be needed and in the place file I sent I did this. The error wasn’t coming from it trying to check a script for the light though.

I’ve realised that your script of changing the brightness would run only once after waiting 2 seconds, but my game takes longer to load and so I’ve modified the script myself.Check above.

I realize this. I was doing that for testing so I could see it change, and I didn’t worry about it looping since I was just trying to fix the initial problem.

1 Like

Finally after a long long time, I’ve came to the final solution.

Turns out everything that was missing was a while true do loop and a :IsA() function.

Here is the code if someone is interested:

task.wait(1)

for _, light in script.Parent:GetChildren() do
	task.spawn(function()
		if light:IsA("Part") then
			while true do
				task.wait(0.2)
				light.SpotLight.Brightness = 0
				task.wait(0.2)
				light.SpotLight.Brightness = 5
			end
		end
	end)
end

And,
Thank you, @FloofyNezzled , @ArchieStatixx , @Scottifly and @TheSai_ki for helping me solve this problem, my appreciation for all of you.

2 Likes

Glad you got it figured out!
although it’s still extremely odd that the place file I sent didn’t work considering this is basically the exact script I used minus the while loop (which won’t affect anything)

No, no , no it worked but I couldn’t see. You set the code to run after 2 seconds but it takes more time for my game to load, and the code was running once meaning that I couldn’t see the change after 1 second(unless I rejoin). And I’ve just made the timer bigger and that’s all.

1 Like

Oh, I see. The 2 seconds was only for me to be able to test it, I was assuming you would change that (same with the loop). The purpose of it wasn’t to be a final result, it was supposed to be a fix to the indexing issue. I thought you were saying it was throwing an error :sweat_smile:

Yes, good to know you figured it out, but what I was suggesting for the flickering effect was this:

Create a folder or model with a specific name in the workspace
Put all your light parts in the folder/model
set a variable for the Brightness to 1 (or whatever)

Make a while true do loop
Put the Spotlights into a pair loop and then change the Brightness value using the variable you set previously.
wait however many seconds
Change the variable using:

if variable == 1 then 
    variable = 5
else 
    variable = 1
end

end the while true do loop, which doesn’t end it, it just goes back to the start and does it all over again but with the Brightness value reversed.

Yes, of course, good advice to know!
But I also need to mention that the script must have a task.spawn() function so that it could take all the parts and change their spotlight brightness value to 1 and 5, at the same time, not in order.

I’m glad you figured it out in the end.

1 Like

Sorry, I didn’t write it as code, just notes.

What I said was run through the loop which would change all the lights in the folder or model in the loop at the same time, then outside the loop wait however many seconds, change the variable, and go back to the loop again with the variable changed.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.