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

[.Changed] Detecting Player's Health Changing?

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)

1 comment

0

Did you thumbs down my comment? If so, since it works, atleast remove the thumbs down.

2 answers

✓ Accepted answer

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!

2 comments

0

Its funny because if any of you tested these script they dont work

0

I forgot to put it in StarterGui. Sorry for the last comment!

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)

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