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

Why is my remote event being detected multiple times?

local explosion = nil
local tool = script.Parent
local DuplicatePrevention = {}
local player = tool.Parent.Parent
script.Parent.Activated:Connect(function(Activated)
	game.ReplicatedStorage.RemoteEvent:FireClient(player)
	print("Fired Client")
	Activated = nil
	game.ReplicatedStorage.ILikeBEaNs.OnServerEvent:Connect(function(plr, target)
		print("Client Returned")
		if plr == player then
			if player.Character:FindFirstChild("Humanoid") then
				if player.Character.Humanoid.Health > 0 then
					print(target)
					if target and target.Parent and target.Parent:FindFirstChild("Humanoid") then
						target.Parent.Humanoid.Health = 0
					end
					plr = nil
					target = nil
				end
			end
		end
	end)
end)

This is my code. Everything is working fine, but it prints "Client returned" multiple times. The code is returning 1 the first time. 2 the second time, 3 the third time, 4 the fourth time, so on. 16:35:29.154 Fired Client - Server - Script:7

16:35:29.239 Client Created Value - Client - LocalScript:6

16:35:29.239 Client Fired Event - Client - LocalScript:8

16:35:29.254 Client Returned - Server - Script:10 -- the first time

16:35:29.254 Baseplate - Server - Script:14

16:35:29.255 Client Returned - Server - Script:10 -- this is the second click so it returned again

16:35:29.255 Baseplate - Server - Script:14

Any idea why this happens?

1 comment

0

oops forgot the localscript

1 answer

✓ Accepted answer

use deactivate function when it becomes activated!

1 comment

0

Thank you for the answer :D I figured it out using a debounce but this also works, I completely for got that. THX :DDD

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