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 4 years ago

if having trouble with this script, :C

01local isTouched = false
02 
03local alreadyPro = game.Workspace.Characters.AlreadyPro.HitBox
04 
05local onCollision = function(collidedPart)
06    -- "OI WOTCHIT WILL YA"
07 
08    local partParent = collidedPart.Parent
09    -- Look for a humanoid in the parent
10    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
11    print(humanoid)
12 
13    if isTouched == false and humanoid then
14        print('touched already pro')
15        game:GetService("Chat"):Chat(game.Workspace.Characters.AlreadyPro.Head, "OI WOTCHIT WILL YA", Enum.ChatColor.White)
View all 22 lines...

1 answer

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

Answer: You need a Debounce.

01local isTouched = false
02 
03local alreadyPro = game.Workspace.Characters.AlreadyPro.HitBox
04 
05local debounce = true -- initialize debounce
06local onCollision = function(collidedPart)
07    -- "OI WOTCHIT WILL YA"
08 
09    local partParent = collidedPart.Parent
10    -- Look for a humanoid in the parent
11    local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
12    print(humanoid)
13 
14    if debounce and isTouched == false and humanoid then
15        debounce = false -- lock debounce
View all 24 lines...

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