yes, i think its gonna work now
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
Yaayyy! It works!! Thank you so muchhh! But I am still facing an issue, the screen effects and the speed slowing down donât seem to work when damaged.
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?
my bad
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
Nice game design also, reminds me of Silent Hill ps1 lol
So the player can run at the same top speed even while damaged?
Yeah itâs supposed to be horror, Iâm glad you picked up the vibe I was going for!
No when damaged your speed is only 3, you canât go any faster than that
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)
Thats it, tell me if there are bugs.
Also, you gotta know how to script if you really want to make that game work e.e
So should it look like this?
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)
Yeah, i think thats what we want. Test it
It seems to boost the speed the first time to 30 but it doesnât bring it back after finishing holding ctrl
does it shows anything on output now?
Ah ok, there is still the error about the Humanoid reference.
On some message above I saw that the Humanoid variable is defined wrong on the Damage script.
At line 12, change
local Humanoid = player.Character.Humanoid.Health
to
local Humanoid = player.Character.Humanoid
And at the running script, i just saw you replaced the InputEnded event for a duplicated InputBegan event. Bring back your input ending function D:
UIS.InputEnded:connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftControl and Humanoid.Health >= 30 then
Character.Humanoid.WalkSpeed = 10
PlayAnim:Stop()
end
end)