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!