updateEffects() is the function handling the damage, so you can put the call inside there.
local lastHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function(health)
if health < lastHealth then
updateEffects()
end
lastHealth = health -- save for the next change
end)
sinse you does not have a variable called Humanoid, you can use
local player = game.Players.LocalPlayer
local blurEffect = game.Lighting.Blur
local colorCorrectionEffect = game.Lighting.ColorCorrection
local sound = workspace.Heartbeatsound
local isPlayerDead = false
local Image = player.PlayerGui.Damage2.ImageLabel
local Sprint = game.StarterGui.ReadMe
local UIS = game:GetService("UserInputService")
local Humanoid = player.Character.Humanoid.Health
-- your updateEffectsFunction would be like
local function updateEffects()
if isPlayerDead then return end
if player.Character.Humanoid.Health < 30 then
blurEffect.Size = 10
colorCorrectionEffect.Brightness = -0.1
colorCorrectionEffect.TintColor = Color3.new(1, 0.537255, 0.537255)
sound:Play()
player.Character.Humanoid.WalkSpeed = 3
Image.Visible = true
Sprint.Disabled = true
else
blurEffect.Size = 0
colorCorrectionEffect.TintColor = Color3.new(1, 1, 1)
sound:Stop()
player.Character.Humanoid.WalkSpeed = UIS:IsKeyDown(Enum.KeyCode.LeftControl) and 30 or 10
Image.Visible = false
Sprint.Disabled = false
end
end
local lastHealth = Humanoid.Health
Humanoid.HealthChanged:Connect(function(health)
if health < lastHealth then
updateEffects()
end
lastHealth = health -- save for the next change
end)
wait, there is still going to be a problem. “updateEffects()” function also handles when the player gets healed above 30, that is the case of a healing and the function only runs when damage. Sorry, let me reorganize and i will send you
This might work for getting out of damaged state also.
local player = game.Players.LocalPlayer
local blurEffect = game.Lighting.Blur
local colorCorrectionEffect = game.Lighting.ColorCorrection
local sound = workspace.Heartbeatsound
local isPlayerDead = false
local Image = player.PlayerGui.Damage2.ImageLabel
local Sprint = game.StarterGui.ReadMe
local UIS = game:GetService("UserInputService")
local Humanoid = player.Character.Humanoid.Health
local isDamaged = false
local lastHealth = Humanoid.Health
local function OnDamage()
isDamaged = true
blurEffect.Size = 10
colorCorrectionEffect.Brightness = -0.1
colorCorrectionEffect.TintColor = Color3.new(1, 0.537255, 0.537255)
sound:Play()
player.Character.Humanoid.WalkSpeed = 3
Image.Visible = true
Sprint.Disabled = true
end
local function NoDamge()
isDamaged = false
blurEffect.Size = 0
colorCorrectionEffect.TintColor = Color3.new(1, 1, 1)
sound:Stop()
player.Character.Humanoid.WalkSpeed = UIS:IsKeyDown(Enum.KeyCode.LeftControl) and 30 or 10
Image.Visible = false
Sprint.Disabled = false
end
NoDamage() -- updates the first time on spawn
Humanoid.HealthChanged:Connect(function(health)
if health < 30 and not isDamaged then
OnDamage()
elseif health >= 30 and isDamaged then
NoDamage()
end
lastHealth = health -- save for the next change
end)
For the screen effect not working, please open the Output window, you can enable that window in the View tab, see if there are any errors related to that.
Also, for the running script, you also need to change this line:
Character.Humanoid.WalkSpeed = 10
to
Character.Humanoid.WalkSpeed = Humanoid.Health < 30 and 3 or 10
Also, how do you want it to behave when you press the Run button while damage? Currently, speed goes to 30 even while damaged. You want a lower speed or disable running when damaged?
Originally while damaged the speed would be 3, and when the play regenerates above 20 HPs their normal speed would be 10 and if you hold shift your speed is boosted to 30
Alright, so you need to disable the speed going to 30 when you press shift while your health is low.
adding only this check might be enough
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.Health >= 30 then
Character.Humanoid.WalkSpeed = 30
local Anim = Instance.new('Animation')
Anim.AnimationId = 'Id'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)
local UIS = game:GetService('UserInputService')
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Player.Character.Humanoid
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.Health >= 30 then
Character.Humanoid.WalkSpeed = 30
local Anim = Instance.new('Animation')
Anim.AnimationId = 'Id'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)
UIS.InputBegan:connect(function(input)--When a player has pressed LeftShift it will play the animation and it will set the normal walking speed (16) to 35.
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.Health >= 30 then
Character.Humanoid.WalkSpeed = 10
local Anim = Instance.new('Animation')
Anim.AnimationId = 'Id'
PlayAnim = Character.Humanoid:LoadAnimation(Anim)
PlayAnim:Play()
end
end)