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

How do I make this where it doesn't spam stun people?

Asked by 4 years ago
01local HitT = true
02 
03function OnTouched(part)
04    local humanoid = part.Parent:FindFirstChild("Humanoid")
05    script.Parent.Hit:Play()
06    if (humanoid ~= nil) then
07        if HitT then
08            HitT = false
09        humanoid.PlatformStand = true
10        print("he touched me")
11    wait(2)
12    humanoid.PlatformStand = false
13            HitT = true
14        end
15    end
16end
17 
18script.Parent.Touched:connect(OnTouched)

no error btw.

1 answer

Log in to vote
1
Answered by 4 years ago

Use a debounce.

01local HitT = true
02local db = false
03local waitTime = 1 --how long to wait so that it doesn't spam stun
04function OnTouched(part)
05    if db then
06    return nil end
07    db = true
08    local humanoid = part.Parent:FindFirstChild("Humanoid")
09    script.Parent.Hit:Play()
10    if (humanoid ~= nil) then
11        if HitT then
12            HitT = false
13        humanoid.PlatformStand = true
14        print("he touched me")
15    wait(2)
View all 24 lines...
Ad

Answer this question