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!
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)