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

Why isn't this Low HP Blur local script not working?

I'm trying to make a Low HP Blur local script, but it won't work. I don't know why! It shows no errors, but there is one and it isn't being pointed out by ROBLOX Studio at all. Not even the output logs/developer console points the error out.

P.S: The local script is in a folder, and so is the blur effect

Script:

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local effect = script.Parent.Blur
cam = workspace.CurrentCamera
effect.Parent = cam

if char.Humanoid.Health <= 30 then
	effect.Enabled = true
elseif char.Humanoid.Health > 30 then
	effect.Enabled = false
end

7 comments

0

Pretty sure the local script has to be in the 'Starter Gui.'

0

I put it at StarterGui, and it still doesn't work.

0

Is the Local Script put seperate from the Folder? So It's just by itself in there.

0

Infact, yes. I made it separate from the folder.

0

heh plz = game.Players.LocalPlayer, that is depricated in my game.. it never works O.o sooo just say game:GetService("Players").LocalPlayer and maybe you should first clone effect O.o before putting it in the local camera

0

plr*

0

Made it clone the effect, and made it moments later be put in the local camera. also did game:GetService("Players").LocalPlayer, i don't think it worked.

1 answer

✓ Accepted answer

You may want to connect this to the HealthChanged event of the Humanoid. Otherwise, this will only fire once.

Also, since you probably want to restart this effect every time the player dies, you should have this under StarterCharacterScripts so that it spawns with the Character. You can also try using the CharacterAdded event for this, though in that case it won't be in StarterCharacterScripts, but instead it will be in StaterPlayerScripts.

Here's how I would probably write the script:

-- Parent this to StarterCharacter. The blur is a child of this script that may be 
-- cloned to CurrentCamera if it hasn't been yet. It's named "HealthBlur"

local Character = script.Parent
local HealthBlurBase = script:WaitForChild("HealthBlur")
local Humanoid  = Character:WaitForChild("Humanoid")
local CurrentCamera = workspace.CurrentCamera

local HealthBlur = CurrentCamera:FindFirstChild("HealthBlur")
if not HealthBlur then
	HealthBlur = HealthBlurBase:Clone()
	HealthBlur.Parent = CurrentCamera
end

HealthBlur.Enabled = false

local function UpdateHealthBlur(newHealth)
	if newHealth > 30 then
		HealthBlur.Enabled = false
	else
		HealthBlur.Enabled = true
	end
end


Humanoid.HealthChanged:Connect(UpdateHealthBlur)
UpdateHealthBlur(Humanoid.Health)

As a design choice, the blur should probably be triggered at a certain percentage of max health.

1 comment

0

You sir, saved my life.

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