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

How would I make my script have a debounce?

Asked by 2 years ago

My script makes a NPC say something when a proximity prompt is run, but I want a debounce. I am not too familiar with debounces, but I feel like I could use some help.

I know I could use HoldDuration, but that could break upcoming scripts that may be added.

This is my current script:

local Chat = game:GetService("Chat")
local messages = {
    "Welcome to Bloxy Mart!",
    "Hello and welcome to Bloxy Mart!",
    "Salutations, welcome to Bloxy Mart!",
    "Having a fine day? Welcome to Bloxy Mart!"
}

script.Parent.Triggered:Connect(function(playerWhoTriggered)
    Chat:Chat(script.Parent.Parent.Parent.Head, messages[math.random(#messages)])
end)

Any help to add a debounce? If so please answer this question. Thank you!

0
If you're not going to use "playerWhoTriggered", then I suggest removing the parameter. Ziffixture 6913 — 2y

1 answer

Log in to vote
-1
Answered by 2 years ago

add these into the script:

local debounce = false -- new variable

local Chat = game:GetService("Chat")
local messages = {
    "Welcome to Bloxy Mart!",
    "Hello and welcome to Bloxy Mart!",
    "Salutations, welcome to Bloxy Mart!",
    "Having a fine day? Welcome to Bloxy Mart!"
}

script.Parent.Triggered:Connect(function(playerWhoTriggered)
    if debonce == false then -- check
        debounce == true --set it so it wont work
        Chat:Chat(script.Parent.Parent.Parent.Head, messages[math.random(#messages)])
        wait() -- wait
            debounce == false -- works again
    end
end)
0
"==" is the equality operator, you cannot use it to make assignments. "wait" has also been superseded by "task.wait". On top of that, you should be specifying a duration. Ziffixture 6913 — 2y
1
Looks like it works! Thanks for helping, I learnt something new as always. :) cool1234great 3 — 2y
Ad

Answer this question