edit: game link health test thingy - Roblox
script that plays an anim depending on your health basically is sometimes working (you can play the game yourself) here is the main script:
local char = game.Players.LocalPlayer.Character
local humanoid = game.Players.LocalPlayer.Character.Humanoid
local currentHealth = humanoid.Health
local anim = char:WaitForChild("Animate")
humanoid.HealthChanged:Connect(function(health)
while true do
wait()
if health <= 50 then
anim.walk.WalkAnim.AnimationId = "rbxassetid://6541469256"
anim.idle.Animation1.AnimationId = "rbxassetid://6540817358"
game.Lighting.ColorCorrection.Saturation = -.5
game.Workspace.Sound.Playing = true
humanoid.WalkSpeed = 12
elseif health >=50 then
anim.walk.WalkAnim.AnimationId = "rbxassetid://180426354"
game.Lighting.ColorCorrection.Saturation = 0
game.Workspace.Sound.Playing = false
anim.idle.Animation1.AnimationId = "rbxassetid://180435571"
humanoid.WalkSpeed = 16
end
end
end)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
game.Workspace.Sound.Playing = false
wait(1)
game.Workspace.Sound.Playing = false
end)
end)
end)
There’s a few things I’m not understanding in your code
Why are you disabling the sound, waiting a second, and then trying to disable it here?
Also why is there a while true do loop in your Healthchanged event?
Try this perhaps?
local char = game.Players.LocalPlayer.Character
local humanoid = char.Humanoid
local currentHealth = humanoid.Health
local anim = char:WaitForChild("Animate")
humanoid.HealthChanged:Connect(function(health)
if health <= 50 then
anim.walk.WalkAnim.AnimationId = "rbxassetid://6541469256"
anim.idle.Animation1.AnimationId = "rbxassetid://6540817358"
game.Lighting.ColorCorrection.Saturation = -.5
game.Workspace.Sound.Playing = true
humanoid.WalkSpeed = 12
else
anim.walk.WalkAnim.AnimationId = "rbxassetid://180426354"
game.Lighting.ColorCorrection.Saturation = 0
game.Workspace.Sound.Playing = false
anim.idle.Animation1.AnimationId = "rbxassetid://180435571"
humanoid.WalkSpeed = 16
end
end)
game:GetService('Players').PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
character:WaitForChild("Humanoid").Died:Connect(function()
game.Workspace.Sound.Playing = false
wait(1)
game.Workspace.Sound.Playing = false
end)
end)
end)
Another thing I saw was that you were checking health is less than or equal to 50 and then an elseif for checking it’s greater than or equal to 50 when I think it’s better if you just did an else
Anytime! It was a bit odd to see a while true do loop there since it doesn’t really need to be there since HealthChanged runs when your health changes of course. If you have anymore issuess don’t be afraid to make another post!
I accidentally edited my post instead of sending a new one to say my usual for when I help someoen with their problem haha. But again, anymore issues, don’t be afraid to make another post!
really quick in the if health <= 50 then i added game.Workspace["Winds of Fjords"].PitchShiftSoundEffect.Octave = .5 and it doesnt seem to work, no errors btw
same sound but one is in workspace and one is in replicated storage, anyways, how could i put another if statement, like if the players health is less then 10 else, then basically the other code for less than 50, then after you heal from that, the else statement for when your health is above 50