Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 7 years ago

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
0
Pretty sure the local script has to be in the 'Starter Gui.' xEiffel 280 — 7y
0
I put it at StarterGui, and it still doesn't work. MeleeSoul 14 — 7y
0
Is the Local Script put seperate from the Folder? So It's just by itself in there. xEiffel 280 — 7y
0
Infact, yes. I made it separate from the folder. MeleeSoul 14 — 7y
View all comments (3 more)
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 greatneil80 2647 — 7y
0
plr* greatneil80 2647 — 7y
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. MeleeSoul 14 — 7y

1 answer

Log in to vote
0
Answered by
XAXA 1569 Moderation Voter
7 years ago
Edited 7 years ago

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.

0
You sir, saved my life. MeleeSoul 14 — 7y
Ad

Answer this question