Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to make damage script only function when character is damaged?

Asked by 4 years ago

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.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
p = ReplicatedStorage:FindFirstChild("YellowPoof")
local tweeninfo = TweenInfo.new(0.85)
local ts = game:GetService("TweenService")
local goal = {}
goal.Size = Vector3.new(11, 11, 11)
goal.Transparency = 1
db = true

function onHurt()
    if db == true then
        db = false
        local humanoid = script.Parent.Humanoid
        local p2 = p:Clone()
        local tween = ts:Create(p2, tweeninfo, goal)
        p2.Parent = workspace
        p2.Position = humanoid.Parent.HumanoidRootPart.Position
        tween:Play()
        if humanoid.RigType == Enum.HumanoidRigType.R15 then
            local animation = humanoid:LoadAnimation(script.Animation)
            animation:Play()
        elseif humanoid.RigType == Enum.HumanoidRigType.R6 then
            local animation = humanoid:LoadAnimation(script.Animation2)
            animation:Play()
        end
        humanoid.Jump = true
        humanoid.WalkSpeed = 10
        wait(1.85)
        humanoid.WalkSpeed = 19.5
        p2:Destroy()
        db = true
end
end
script.Parent.Humanoid.HealthChanged:Connect(onHurt)

1 answer

Log in to vote
0
Answered by
Zikelah 20
4 years ago

Well, for a damage script: EXAMPLE

local LavaBox = script.Parent
local DamageAmount = 10 -- you can change that

local function DealDamage(part)
    local hum = part.Parent:FindFirstChild("Humanoid)
    if hum then
        hum.Health - DamageAmount
    end
end
LavaBox.Touched:Connect(DealDamage)

and for fling, try this

Player.pos = (0, 5000, 0) -- can be changed
0
I already know how to make parts damage players. What I want to know is how to trigger a script inside a character when the player is damaged DogeIsDohj 10 — 4y
Ad

Answer this question