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

[.Changed] Detecting Player's Health Changing?

Asked by 9 years ago

Im just trying to mess around with .Changed because I've never used it. Can Anyone fix this please? :D

local Player = game.Players.LocalPlayer
local Character = (function() repeat wait() until Player.Character return Player.Character end)()
local camera = game.Workspace.CurrentCamera
local FOV = 70
character.Humanoid.Changed:connect(function(Change)
    if Change:match("Health") then  
    FOV = FOV -70
    camera.FieldOfView = FOV
end
end)
0
Did you thumbs down my comment? If so, since it works, atleast remove the thumbs down. EzraNehemiah_TF2 3552 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

Easy, instead of using :match() just check if Change == "Health". Another problem was that Character on line 2 had a Capital C and the other character on line 5 had a lower cased one. Also, the minimum value for FOV is 1, it cannot go over 120 or under 1.

local Player = game.Players.LocalPlayer
local Character = (function() repeat wait() until Player.Character return Player.Character end)()
local camera = game.Workspace.CurrentCamera
local FOV = 70
Character.Humanoid.Changed:connect(function(Change)
    if Change == "Health" then  
    FOV = FOV -69
    camera.FieldOfView = FOV
end
end)

If you want it so that if a player dies then use the Died event.


BTW I revised your whole script.

local Player = game.Players.LocalPlayer
local Character = (function() repeat wait() until Player.Character return Player.Character end)()
local camera = game.Workspace.CurrentCamera
Character.Humanoid.Changed:connect(function(Change)
    if Change == "Health" then  
    camera.FieldOfView = 1
end
end)

Hope this helps!

0
Its funny because if any of you tested these script they dont work Timster111 25 — 9y
0
I forgot to put it in StarterGui. Sorry for the last comment! Timster111 25 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
local Player = game.Players.LocalPlayer
local Character = Player.CharacterAdded:wait()
local Humanoid = Character:WaitForChild("Humanoid")
local Camera = game.Workspace.CurrentCamera

local currentHealth = Humanoid.Health

Humanoid.HealthChanged:connect(function(health)
    local change = math.abs(currentHealth - health)
    if currentHealth > health then
        --health decreased!
        print(change.."damage")
    else
        --health increased
        print(change.."heal")
    end
    currentHealth = health
end)

Answer this question