How could I make the player have to stop and play an animation when taking damage?
Make sure this is in a localscript and is either placed in StarterCharacterScripts or StarterPlayerScripts.
I hope I've helped you out.
local Humanoid = game.Players.LocalPlayer.Character.Humanoid local currentHealth = Humanoid.Health local DamageAnimation = "rbxassetid://1764222386" local function PlayAnimation(AnimationId) local Animation = Instance.new("Animation") Animation.AnimationId = AnimationId Animation.Name = AnimationId local LoadAnim = Humanoid:LoadAnimation(Animation) LoadAnim:Play() end local function StopAnimation(AnimationId) for index, child in pairs(Humanoid:GetPlayingAnimationTracks()) do if string.match(DamageAnimation, child.Name) then child:Stop() end end end Humanoid.HealthChanged:connect(function(health) local change = math.abs(currentHealth - health) if change >= 45 then PlayAnimation(DamageAnimation) end if health > 65 then StopAnimation(DamageAnimation) end currentHealth = health end)