Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.