Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Help me prevent spamming this dialog script! [Easy fix] ?

I have this script that you can click and it will read a dialog, But you can spam it and its so game breaking! Please help

local part = script.Parent
part.Parent = game.Workspace
local ChatService = game:GetService("Chat")
function Clicked(player)
    ChatService:Chat(part, ("Hi there "..player.Name), "Red")
wait (2)
ChatService:Chat(part, ("How can i help you?"),"Red")
end


script.Parent.ClickDetector.MouseClick:connect(Clicked)

4 answers

✓ Accepted answer
local part = script.Parent
local Debounce = false
part.Parent = game.Workspace
local ChatService = game:GetService("Chat")
function Clicked(player)
    if Debounce == false then
       ChatService:Chat(part, ("Hi there "..player.Name), "Red")
       Debounce = true
       wait (2)
       ChatService:Chat(part, ("How can i help you?"),"Red")
       Debounce = false
    end
end


script.Parent.ClickDetector.MouseClick:connect(Clicked)

1 comment

0

Thanks!

To prevent that you can use a debounce.

I hope this helped you.

3 comments

0

How would that help me? Lol

0

Debounce allows a function to be fired once and cannot be fired again for a period of time.

0

Ok Thanks for the information!

StopSpam = true

if not StopSpam then StopSpam = false

wait(1) StopSpam = true end

#Debounce.

You could be using debounce, this way people will only be able to do a certain action on a specific amount of time.

Debounce is structured with booleans, and in your case you would have to do the following:

  • Define a true boolean.

  • Add an if statement which will return nil if the previous boolean hasn't met thetrue condition.

  • Make the previous boolean false.

  • Wait for a specific time.

  • Make it true again.

#Practice:

local canClick = true
local part = script.Parent
part.Parent = game.Workspace
local ChatService = game:GetService("Chat")
function Clicked(player)
if not canClick then return end
canClick = false
ChatService:Chat(part, ("Hi there "..player.Name), "Red")
wait (2)
ChatService:Chat(part, ("How can i help you?"),"Red")
wait(1) --or any time desired (in seconds)
canClick = true
end


script.Parent.ClickDetector.MouseClick:Connect(Clicked)

Another fact is that connect is deprecate. Use Connect instead. You can read about deprecated items here.

1 comment

0

Ok Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.