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)
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)
To prevent that you can use a debounce.
I hope this helped you.
StopSpam = true
if not StopSpam then StopSpam = false
wait(1) StopSpam = true end
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.
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.