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

Damage script help?

Asked by 9 years ago

Okay so I've made a damage script that when you touch a part you're losing 20 health.The bug isn't in the script but I want to make it so like that part damages the character only once. If I destroy the part it works but I don't intend to do it. Any suggestions?

x.Touched:connect(function(Part) 
    if Part.Parent:FindFirstChild("Humanoid") ~= nil and  Part.Parent:FindFirstChild("Humanoid") ~= Player.Character.Humanoid  and Part.Parent.Name ~= "Wall"  then
        Part.Parent.Humanoid.Health = Part.Parent.Humanoid.Health-20
        end
end)
0
This is in a Script right? woodengop 1134 — 9y
0
Yeah it's the damaging part of the script. brokenrares 48 — 9y
0
please post more code (like the x variable) and the error you get davness 376 — 9y
0
I don't get any error..... It's just that it damages the character when it touches until he touches it no more.... If I destroy the part I prevent this but I don't want to... also if I put script.Disabled = true and after Script.Disabled = false it's annoying. brokenrares 48 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

First: Don't Do The Damage Like That, Use:

humanoid:TakeDamage(20)

Second, you should use hit:

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:TakeDamage(20)
    end
end)

Also, if you want it to make just 20 Damage, you should use script.Disabled:

script.Parent.Touched:connect(function(hit)
    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid then
        humanoid:TakeDamage(20)
        script.Disabled = true
        wait(2)
        script.Disabled = false
    end
end)

There, works. Also, If you copy my script, then you have to put it in the part.

You're Welcome,

SwaggyDuckie

0
Do not use 'script.Disabled' to Debounce codes; It won't beable to Enable itself again! TheeDeathCaster 2368 — 9y
Ad

Answer this question