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

How to stop script sending multiple webhooks?

Hi,

Im very new to Lua And im trying to make a script that sends a webhook when you touch a brick, However When the player touches the brick it sends Multiple webhooks, Is there a way I can only make it send 1 Webhook?

Heres the code:

local url = "[url]"
local http = game:GetService("HttpService")
script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent
		
		local data = {
		['embeds'] = { {
			["title"] = "ATTEMPTED BREACH",
				["description"] = "ALERT: ["..Player.Name.."] has Tried to enter The [REDACTED] Sector. /n Apprehend "..Player.Name.." **NOW**",
						["color"] = 16711680;
						["image"] = {
							["url"] = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&username="..Player.Name
						};
						["footer"] = {
							["text"] = "Alert Triggered by "..Player.Name,
				
							}
						}
		}
		
	} local finaldata = http:JSONEncode(data)
		http:PostAsync(url, finaldata)		
	end
end)

2 answers

✓ Accepted answer

#Debounce

You put a .Touched event on line 3, this will fire multiple times as you did not establish a debounce.

Just put a debounce in the script, and it should be solved :)

2 comments

0

Thank You Very much!

0

No problem man!

Like Calculati0n said, use a debounce.

debounce example without cooldown but only activates once per character

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild('WEBHOOKDEBOUNCE') then return end
-- add code inside here for testing if humanoid and player and add the webhook code.
end)

and add this inside the if for if its a player:

local bool = Instance.new('BoolValue', hit.Parent)
bool.Name = "WEBHOOKDEBOUNCE" -- creates a bool called webhook debounce, this is our debounce. it will work if you reset.

debounce example with just a cooldown

local cooldown = 5
script.Parent.Touched:Connect(function(hit)
	
	if cooldown_ then return end -- debounce
	
	if game.Players:FindFirstChild(hit.Parent.Name) and hit.Parent:FindFirstChild('Humanoid') then
		cooldown_ = true
		-- webhook code (only) in here!!
		wait(cooldown)
		cooldown_ = false
    end
end)

These are merely simple examples, but either one should work.

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