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 5 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.

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02p = ReplicatedStorage:FindFirstChild("YellowPoof")
03local tweeninfo = TweenInfo.new(0.85)
04local ts = game:GetService("TweenService")
05local goal = {}
06goal.Size = Vector3.new(11, 11, 11)
07goal.Transparency = 1
08db = true
09 
10function onHurt()
11    if db == true then
12        db = false
13        local humanoid = script.Parent.Humanoid
14        local p2 = p:Clone()
15        local tween = ts:Create(p2, tweeninfo, goal)
View all 34 lines...

1 answer

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

Well, for a damage script: EXAMPLE

01local LavaBox = script.Parent
02local DamageAmount = 10 -- you can change that
03 
04local function DealDamage(part)
05    local hum = part.Parent:FindFirstChild("Humanoid)
06    if hum then
07        hum.Health - DamageAmount
08    end
09end
10LavaBox.Touched:Connect(DealDamage)

and for fling, try this

1Player.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 — 5y
Ad

Answer this question