How to make damage script only function when character is damaged?
I made a script that launches a player into the air when they get damaged. The problem is that it happens when the player is healed too. I have tried things like "if humanoid.Health < Health" but they all didn't work. It'd be great if someone helped me. The script is inserted inside the character model.
01 | local ReplicatedStorage = game:GetService( "ReplicatedStorage" ) |
02 | p = ReplicatedStorage:FindFirstChild( "YellowPoof" ) |
03 | local tweeninfo = TweenInfo.new( 0.85 ) |
04 | local ts = game:GetService( "TweenService" ) |
06 | goal.Size = Vector 3. new( 11 , 11 , 11 ) |
13 | local humanoid = script.Parent.Humanoid |
15 | local tween = ts:Create(p 2 , tweeninfo, goal) |
17 | p 2. Position = humanoid.Parent.HumanoidRootPart.Position |
19 | if humanoid.RigType = = Enum.HumanoidRigType.R 15 then |
20 | local animation = humanoid:LoadAnimation(script.Animation) |
22 | elseif humanoid.RigType = = Enum.HumanoidRigType.R 6 then |
23 | local animation = humanoid:LoadAnimation(script.Animation 2 ) |
27 | humanoid.WalkSpeed = 10 |
29 | humanoid.WalkSpeed = 19.5 |
34 | script.Parent.Humanoid.HealthChanged:Connect(onHurt) |