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

Why my damage script only damages a single person when several players touch it?

Asked by 5 years ago

I am using a debounce for this, I don't want the part spam :TakeDamage(10) making it unfair, it is also unfair because a single unlucky person will get hit. I want to make the part damage several players without making the part spam alots of :TakeDamage() making the part overpowered. Here's an example:

local debounce = false
script.Parent.Touched:Connect(function(hit)
    local human = hit.Parent:FindFirstChildOfClass("Humanoid")
    if hit.Parent.Name ~= "cherrythetree" then
        if human and debounce == false then
            debounce = true
            human:TakeDamage(10)
            wait(2)
            debounce = false
        end
    end
end)

Anyone help???

0
ur debounce is wrong TheluaBanana 946 — 5y
0
ur script is basically saying once one player touches it, it will wait 2 seconds before accepting the input of another player touching it TheluaBanana 946 — 5y
0
So what will I use? else or wait(2) or disable debounce? cherrythetree 130 — 5y
0
have the debounce on the client side or have a plr debounce list TheluaBanana 946 — 5y
View all comments (3 more)
0
ur method works fine when there is only one guy touching the thing TheluaBanana 946 — 5y
0
however when a lot of people touch it at once the logic will tell u it cant simultaneously damage them all TheluaBanana 946 — 5y
0
Use coroutines. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

You could make the debounce per-player instead of just having one variable.

local debounce_container = {}

script.Parent.Touched:Connect(function(hit)
    local human = hit.Parent:FindFirstChildOfClass("Humanoid")
    local name  = hit.Parent.Name
    if name ~= "cherrythetree" then
        if human and debounce_container[name] ~= true then
            debounce_container[name] = true
            human:TakeDamage(10)
            wait(2)
            debounce_container[name] = false
        end
    end
end)
0
Thanks! I forgot to rename the two villagers with the same name so the script won't be confused. So I accidently unaccepted for thinking it did not work. cherrythetree 130 — 5y
Ad

Answer this question