I am not asking for a full script, I am asking how to make something happen when a player has taken damage.
2 Likes
game:GetService("Players").LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
end)
2 Likes
wouldn’t that do it if they healed too?
1 Like
yes but u can check current healt by if statements
1 Like
if humanoid.health >= humanoid.health then
like this?
1 Like
would this work?
game:GetService("Players").LocalPlayer.Character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if game.Players.LocalPlayer.Character.Humanoid.Health <= game.Players.LocalPlayer.Character.Humanoid.Health then
local plr = game.Players.LocalPlayer
local orgclr = Instance.new("Color3Value")
orgclr.Color = Color3.fromRGB(plr.Character.Head.Color)
local flash = plr.Character:GetChildrenOfClass("MeshPart")
flash.Color = Color3.fromRGB(255, 0, 0)
wait(0.2)
flash.Color = orgclr
end
end)
To know the amount changed you have to keep track of the previous health in a separate variable.
local character = game.Players.LocalPlayer.Character
local storedHealth = character.Humaoid.Health
character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if (character.Humanoid.Health > storedHealth) then
print("health has increased")
elseif (character.Humanoid.Health < storedHealth) then
print("health has decreased")
end
storedHealth = character.Humanoid.Health
end))
3 Likes
Ok the script looks like this now, but it still does not work…
local character = game.Players.LocalPlayer.Character
local storedHealth = character.Humaoid.Health
character.Humanoid:GetPropertyChangedSignal("Health"):Connect(function()
if (character.Humanoid.Health > storedHealth) then
print("healthgained")
elseif (character.Humanoid.Health < storedHealth) then
local plr = game.Players.LocalPlayer
local orgclr = Instance.new("Color3Value")
orgclr.Parent = script
orgclr.Color = Color3.fromRGB(plr.Character.Head.Color)
local flash = plr.Character:GetChildrenOfClass("MeshPart")
flash.Color = Color3.fromRGB(255, 0, 0)
wait(0.2)
flash.Color = orgclr
end
storedHealth = character.Humanoid.Health
end)
Is this a local script and located outside of workspace?
is localscript in startercharacterscripts
well first of all, you’re setting flash.Color to a color3 value
local orgclr = Instance.new("Color3Value")
…
flash.Color = orgclr
also, :GetChildrenOfClass() doesnt exist
1 Like
What’s wrong with the script? Does it error or just not run at all?
not run at all…