Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

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

Asked by 2 months 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 332 Moderation Voter
2 months ago
Edited 2 months 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