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 3 years ago
local HitT = true

function OnTouched(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    script.Parent.Hit:Play()
    if (humanoid ~= nil) then
        if HitT then
            HitT = false
        humanoid.PlatformStand = true
        print("he touched me")
    wait(2)
    humanoid.PlatformStand = false
            HitT = true
        end
    end
end

script.Parent.Touched:connect(OnTouched)

no error btw.

1 answer

Log in to vote
1
Answered by 3 years ago

Use a debounce.

local HitT = true
local db = false
local waitTime = 1 --how long to wait so that it doesn't spam stun
function OnTouched(part)
    if db then
    return nil end
    db = true
    local humanoid = part.Parent:FindFirstChild("Humanoid") 
    script.Parent.Hit:Play()
    if (humanoid ~= nil) then
        if HitT then
            HitT = false
        humanoid.PlatformStand = true
        print("he touched me")
    wait(2)
    humanoid.PlatformStand = false
            HitT = true
wait(waitTime)
db = false
        end
    end
end

script.Parent.Touched:connect(OnTouched)
Ad

Answer this question