Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Problem with changing blur effect when health changes?


local human = game.Players.LocalPlayer.Character.Humanoid
local blur = game.Lighting.Blur

human.HealthChanged:connect(function(h)
	if (h <= 10) and (h > 0) then
		blur.Size = 11
	elseif (h <=30) and (h > 10) then
		blur.Size = 5
	elseif (h >30) then
		blur.Size = 0
	end

So I'm a new scripter. I'm trying to make a script to make screen blurry depending on LocalPlayer's health. This is being accessed from a LocalScript, FE on. This is what I was told to do on the forums. It did not work. Please correct it!

EDIT: ANSWER AND COMMENT HAVE NOT YET FIXED ISSUE!

8 comments

0

You need to end the health changed event and add ) because of line 4. So line 12 should be "end)".

0

Even after that it still didn't work :c

0

Try wrapping the .HealthChanged event in a .CharacterAdded event. It might not connect when the character dies. Any errors?

0

Beggining scripter, how is this done. Just write out the new line of code.

0

I assume you want each player to have a blur independant of the others?

0

Yes

0

I'm working on it.

0

Alright thanks.

3 answers

As GoldenPhysics commented, you're missing and end after line 11. The end would look like this: end.

Because you're using FE, the blur should not appear for other players when you change it. However, if you were to parent Blur to the players Camera (game.Workspace.CurrentCamera), this would work if FE were to be disabled.

Using Blur inside of lighting still works in this case.

  • Safety Measure;

I suggest you use some WaitForChild() methods. If you're using a localscript then the second this localscript is searching for the character and humanoid, it may not exist and say you're trying to do something with a nil instance. I suggest exchanging line 1 with this:

local Plr = game.Players.LocalPlayer
repeat wait() until Plr.Character.Humanoid -- yield until Humanoid is found
local human = Plr.Character.Humanoid

2 comments

0

They still need a close parenthesis after the end.

0

Sorry what does that mean?

First, as alphawolvess said, it would probably be a good idea to make sure everything exists and wait for it if it doesn't.

local plr = game.Players.LocalPlayer --get the player

for i, v in pairs(workspace.CurrentCamera:GetChildren()) do --loop through the CurrentCamera children
	v:Destroy() --destroy anything inside CurrentCamera
end

repeat wait() until plr.Character --wait for the character
local hum = plr.Character:WaitForChild("Humanoid", 5) --wait no more than five seconds for the humanoid
local blur = game.ReplicatedStorage.Blur:Clone() --clone a blur in replicated storage
--The line above requires a BlurEffect object put in ReplicatedStorage to serve as the original for the copy whenever the player's character loads. I recommend setting the size to 0 as the default.

blur.Parent = workspace.CurrentCamera --set the clone's blur to the CurrentCamera

hum.HealthChanged:connect(function(h) --when the humanoid's health is changed...
	blur.Size = 30-h --set blur size to 30 minus the new health. Also, see notes below.
end)

The next to last line will set the blur based on the new health so that there will be blur if the health is less than 30 and it will blur more if the health is lower. The formula can be changed to set the blur based on whatever formula you want. You could also replace it with an if statement structure like you started with.

Also, you were missing end) in the script you gave us, and that would cause an error before your script even started.

This discussion is preserved as it was. New answers, comments, and votes are closed.