How to intermittently make someone's screen blurry?

I know this is probably kind of weird but basically, I’m trying to make a script that just intermittently makes your screen really blurry, but when I try to test it out, nothing happens. Here’s what I have:

local timeOne = math.random(30,90)
local blurSize = game.Lighting.Blur.Size
while true do
	wait (timeOne)
	repeat
		blurSize = blurSize + 1
	until blurSize >= 25
	if blurSize >= 25 then
		repeat
			blurSize = blurSize - 1
		until blurSize <= 0
	end
end

Also, I don’t really know if I should put the script in the workspace, or as a child of the blur effect, or what since I’m pretty new to scripting.

Uh, Is this a server script or a local script? because I’m pretty sure when editting blue your supposed to do it in a local script.

This needs to be a LocalScript in StarterPlayer > StarterPlayerScripts

If you want this to be more random, you should also calculate math.random() inside your while loop

EDIT:
You should ALSO be using game:GetService("Lighting"), not game.Lighting.

Because u are getting the size of an object adding like that doesnt actually make changes on object size. I would recommend creating a variable named “blur” and assigning an object game.Lighting.Blur now u want to say “blur.Size = blurSize” after adding or substracting that 1 to blur size

Adding on to what @nuttela_for1me said, you should be using for loops.

I’ve also just noticed that you’re accessing Blur.Size, what’s happening here is you’ve copied the value but not the reference.

blurSize is equal to a number, when you update blurSize it updates the number but not the Blur Object.

To fix this, you simply need to do this: (I’ve also added in the properly implemented for loops)

local Blur = game:GetService("Lighting").Blur
while wait(math.random(30, 90)) do
     for i=0, 25 do wait() -- Add a delay so it doesn't run as fast as the environment lets it
          Blur.Size = i
     end
     for i=25, 0, -1 do wait()
          Blur.Size = i
     end
end
4 Likes