FireServer Triggering Multiple Times

I’m trying to make a push tool for my game

And for some reason whenever I activate the tool the FireServer event triggers multiple times

The issue seems to be happening on the client whenever I was debugging it

Client script:

-- Services
local PlayerService = game:GetService("Players")
local DebrisService = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Player
local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid:Humanoid = Character:WaitForChild("Humanoid")
local Animator:Animator = Humanoid:WaitForChild("Animator")

-- Tool
local Tool = script.Parent
local Sounds = script:WaitForChild("PushSounds")
local Animation = script:WaitForChild("Animation")
local HumAnim = Animator:LoadAnimation(Animation)

-- Events
local Remotes = ReplicatedStorage.Remotes
local AttackRemote = Remotes.Attack

-- Variables
local USED = false
local COOLDOWN = 5
local DAMAGE = 5
local KNOCKBACK = 20

-- Functions
function Activated()
	if not USED then
		if Character.Ragdolled.Value ~= true then
			USED = true
			task.delay(COOLDOWN, function()
				USED = false
			end)
			HumAnim:Play()

			HumAnim:GetMarkerReachedSignal("Swing"):Connect(function()
				local NewSound = Sounds.Swing:GetChildren()[math.random(1, #Sounds.Swing:GetChildren())]:Clone()
				NewSound.Parent = Character.HumanoidRootPart
				NewSound:Play()
				DebrisService:AddItem(NewSound, NewSound.TimeLength)
			end)
			HumAnim:GetMarkerReachedSignal("Hit"):Connect(function()
				AttackRemote:FireServer(Vector3.new(5, 5, 4), Character.HumanoidRootPart.CFrame.LookVector * 2, KNOCKBACK, DAMAGE)
			end)
		end
	end
end

-- Connections
Tool.Activated:Connect(Activated)

Server script:

-- Services
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Remotes
local Remotes = ReplicatedStorage.Remotes
local AttackRemote = Remotes.Attack

-- Modules
local Modules = ReplicatedStorage.Modules
local AttackHitboxes = require(Modules.AttackHitboxes)

-- Functions
function CreateHitbox(Player, Size, Position, Knockback, Damage)
	AttackHitboxes.CreateHitbox(Player.Character, Size, Position, Knockback, Damage)
end

-- Connections
AttackRemote.OnServerEvent:Connect(CreateHitbox)

I would appreciate it if someone can help me identify the issue and find a solution!

I really think you should be capturing .Activated on the server instead, because using a RemoteEvent like this is going to make you vulnerable to exploiters.

Regarding your current issue though, how are you sure it’s firing multiple times?

I was using print commands and every time I activated it, It was firing +1 times

debugging stuff -- Activated
debugging stuff -- Activated
debugging stuff
debugging stuff -- Activated
debugging stuff
debugging stuff

You probably get what I mean by this

1 Like

Can you try using :Once instead of :Connect?

-- Services
local PlayerService = game:GetService("Players")
local DebrisService = game:GetService("Debris")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Player
local Player = PlayerService.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid:Humanoid = Character:WaitForChild("Humanoid")
local Animator:Animator = Humanoid:WaitForChild("Animator")

-- Tool
local Tool = script.Parent
local Sounds = script:WaitForChild("PushSounds")
local Animation = script:WaitForChild("Animation")
local HumAnim = Animator:LoadAnimation(Animation)

-- Events
local Remotes = ReplicatedStorage.Remotes
local AttackRemote = Remotes.Attack

-- Variables
local USED = false
local COOLDOWN = 5
local DAMAGE = 5
local KNOCKBACK = 20

-- Functions
local function Activated()
	if not USED then
		if Character.Ragdolled.Value ~= true then
			USED = true
			task.delay(COOLDOWN, function()
				USED = false
			end)
			HumAnim:Play()

			HumAnim:GetMarkerReachedSignal("Swing"):Once(function()
				local NewSound = Sounds.Swing:GetChildren()[math.random(1, #Sounds.Swing:GetChildren())]:Clone()
				NewSound.Parent = Character.HumanoidRootPart
				NewSound:Play()
				DebrisService:AddItem(NewSound, NewSound.TimeLength)
			end)
			HumAnim:GetMarkerReachedSignal("Hit"):Once(function()
				AttackRemote:FireServer(Vector3.new(5, 5, 4), Character.HumanoidRootPart.CFrame.LookVector * 2, KNOCKBACK, DAMAGE)
			end)
		end
	end
end

-- Connections
Tool.Activated:Connect(Activated)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.