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

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

Asked by 5 years ago

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

Log in to vote
0
Answered by
Mr_Unlucky 1085 Moderation Voter
5 years ago
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)
0
Thanks! Vibesgus 35 — 5y
Ad
Log in to vote
0
Answered by
angeI1001 123
5 years ago

To prevent that you can use a debounce.

I hope this helped you.

0
How would that help me? Lol Vibesgus 35 — 5y
0
Debounce allows a function to be fired once and cannot be fired again for a period of time. angeI1001 123 — 5y
0
Ok Thanks for the information! Vibesgus 35 — 5y
Log in to vote
0
Answered by 5 years ago

StopSpam = true

if not StopSpam then StopSpam = false

wait(1) StopSpam = true end

Log in to vote
0
Answered by
piRadians 297 Moderation Voter
5 years ago
Edited 5 years ago

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.

0
Ok Thanks! Vibesgus 35 — 5y

Answer this question