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
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
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
When referencing .Enabled as GlitchEffect, you’re actually referring to the Glitch.Enabledcurrent 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
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.