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

Not taking tat much damage?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

This script takes away 100 health. I want it to take away 50%

script.Parent.Touched:connect(function(Obj) -- When you touch it gets the "Leg" or "Arm"
    local Player = game:GetService("Players"):GetPlayerFromCharacter(Obj.Parent)
    -- Gets the Instance "Player"
    if Player and Player.Character then -- Obv its gonna be there...
        local Humanoid  = Player.Character:WaitForChild("Humanoid") -- Find the Humanoid
        Humanoid:TakeDamage(50) -- Easy damage function.. :)
    end
 end)
0
http://wiki.roblox.com/index.php?title=Debounce has good info & it probably applies to this situation. Redbullusa 1580 — 8y

1 answer

Log in to vote
2
Answered by 8 years ago

you need a debounce, you hit a part like 1 million times in a second, it probaly works, the script is called tonns of times

debounce = false
script.Parent.Touched:connect(function(Obj)
    if debounce == false then
        debounce = true
        local Player = game:GetService("Players"):GetPlayerFromCharacter(Obj.Parent)
            if Player and Player.Character then
                local Humanoid  = Player.Character:WaitForChild("Humanoid")
                Humanoid:TakeDamage(50) 
                wait(3)
                debounce = false
            end
    end
end)

:) try this for half damage

debounce = false
script.Parent.Touched:connect(function(Obj)
    if debounce == false then
        local Player = game:GetService("Players"):GetPlayerFromCharacter(Obj.Parent)
            if Player and Player.Character then
                local Humanoid  = Player.Character:WaitForChild("Humanoid")
                local damage = Humanoid.Maxhealth/2
                Humanoid:TakeDamage(damage) 
                debounce = true
            end
    end
end)
0
I agree, add a debounce. JasonTheOwner 391 — 8y
Ad

Answer this question