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

Make it so it plays once... [or delayed?]

if having trouble with this script, :C

local isTouched = false

local alreadyPro = game.Workspace.Characters.AlreadyPro.HitBox

local onCollision = function(collidedPart)
	-- "OI WOTCHIT WILL YA"
	
	local partParent = collidedPart.Parent
	-- Look for a humanoid in the parent
	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
	print(humanoid)
	
	if isTouched == false and humanoid then
		print('touched already pro')
		game:GetService("Chat"):Chat(game.Workspace.Characters.AlreadyPro.Head, "OI WOTCHIT WILL YA", Enum.ChatColor.White)
		script.Fart:Play()
	end
	isTouched = true
	
end

alreadyPro.Touched:Connect(onCollision)

1 answer

✓ Accepted answer

Answer: You need a Debounce.

local isTouched = false

local alreadyPro = game.Workspace.Characters.AlreadyPro.HitBox

local debounce = true -- initialize debounce
local onCollision = function(collidedPart)
    -- "OI WOTCHIT WILL YA"

    local partParent = collidedPart.Parent
    -- Look for a humanoid in the parent
    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    print(humanoid)

    if debounce and isTouched == false and humanoid then
		debounce = false -- lock debounce
        print('touched already pro')
        game:GetService("Chat"):Chat(game.Workspace.Characters.AlreadyPro.Head, "OI WOTCHIT WILL YA", Enum.ChatColor.White)
        script.Fart:Play()
    end
    isTouched = true

end

alreadyPro.Touched:Connect(onCollision)

Note: You can unlock the debounce whenever you would like. Usually people will wait for something to finish and then allow the debounce to be unlocked. This is done like so: debounce = true.

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