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

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

Asked by 3 years ago

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

Log in to vote
0
Answered by
Roger111 347 Moderation Voter
3 years ago
Edited 3 years ago

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.

Ad

Answer this question