Effects every (random) second

Hey all, adding to my game a glitch effect every few random seconds, after 4 minutes into the game. However this script I made doesn’t seem to work, and I’m sorry if this post is quite stupid but I main on making models more.

wait(240)
while true do

local RandomTime = math.random(30, 60)
local GlitchEffect = game.Lighting.Glitch.Enabled
	
	wait(RandomTime)
	GlitchEffect = true

end

What is glitch a light or a effect? What is the glitch as the random time should work fine.

1 Like

try replace

to: local GlitchEffect = game.Lighting.Glitch

and this

to: GlitchEffect.Enabled = true

or replace script on this:

local GlitchEffect = game.Lighting.Glitch
wait(240)
while true do

local RandomTime = math.random(30, 60)
	wait(RandomTime)
GlitchEffect.Enabled = true
wait(1) --or length of effect
	GlitchEffect.Enabled = false

end
1 Like

The glitch is a ColorCorrectionEffect that is named to “Glitch”, basically making the contrast, saturation and brightness look really weird and stuff.

local Lighting = game:GetService("Lighting")
local GlitchEffect = Lighting.Glitch

while true do
	local RandomTime = math.random(30, 60)
	task.wait(RandomTime)
	GlitchEffect.Enabled = true
	task.wait(0) --Change 0 to length of effect.
	GlitchEffect.Enabled = false
end
1 Like

When referencing .Enabled as GlitchEffect, you’re actually referring to the Glitch.Enabled current value not the property, therefore you aren’t setting the property to true but the GlitchEffect variable value. Instead you should reference the object then set the .Enabled property to true:

task.wait(240) --no idea why this is here
while true do 
	local randomTime = math.random(30, 60)
	local GlitchEffect = game.Lighting.Glitch --you must reference the object not the property!
	task.wait(randomTime)
	GlitchEffect.Enabled = true 
end
1 Like

the wait(240) is for when the player joins the game, after a 4 minutes start doing this task.

That’s fine but you should probably remove long waits when debugging, otherwise each time you want to test you’ll end up needing to wait 4 minutes before anything happens.

1 Like