RemoteEvent fires for every player in the server?

I want to make an attack that does damage.

The problem now is, that the event fires as many times as there are players on the server. So if there are currently three players in the game, my attack does three times as much damage

I’ve tried it with debounce but it doesn’t seem to work like that.

Here is the code: (Client)

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local char = Player.Character or Player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()
local tool = script.Parent
local equipped = false
tool.RequiresHandle = false
local UIS = game:GetService("UserInputService")
local mouse = Player:GetMouse()
local debounce = true

tool.Equipped:Connect(function()
	equipped = true
end)

UIS.InputBegan:Connect(function(Input, GameStuff)
 	if GameStuff then return end
 		if Input.KeyCode == Enum.KeyCode.Q then
			if equipped and debounce then	
				game.ReplicatedStorage.RenewalEvent.RenewalBaekRok:FireServer()
				debounce = false
				wait(0.2)
				for i = 1,5 do
					local a = math.random(-100,100)/500
					local b = math.random(-100,100)/500
					local c = math.random(-100,100)/500
					hum.CameraOffset = Vector3.new(a,b,c)
					wait()
				end
				wait(1.4)
				debounce = true
		end
	end
end)

tool.Unequipped:Connect(function()
	equipped = false
end)

Server:

local Delay = .35
 
game.ReplicatedStorage.RenewalEvent.RenewalBaekRok.OnServerEvent:Connect(function(Player)

local anim = Instance.new("Animation")
anim.AnimationId = "rbxassetid://04555047636"
local animation = Player.Character.Humanoid:LoadAnimation(anim)

local Swoosh = Instance.new('Sound',Player.Character.HumanoidRootPart)
Swoosh.SoundId = 'rbxassetid://231731980'
Swoosh.Volume = .2
Swoosh.EmitterSize = 100

animation:play()
Swoosh:Play()
wait(.2)
local Dmg = script.BaekRok:Clone()
Dmg.Parent = Player.Character["Right Leg"]
Dmg.Disabled = false
wait(Delay)
Dmg.Disabled = true
Dmg:Destroy()
end)
1 Like

The code you’ve provided doesn’t seem to be the problem here.

Would you be able to show the BaekRok Script?

FYI: I recommend against the use of the second argument in the Instance.new constructor. You can read more about that here:

Here’s the code:

local PlayerHRP = script.Parent.Parent.HumanoidRootPart
local Humanoid =script.Parent.Parent.Humanoid

local function findTarget()
	local dist = 100
	local Target = nil
	for i,v in pairs(game.Workspace:GetChildren()) do
		local human = v:FindFirstChild("Humanoid")
		local TargetHRP = v:FindFirstChild("HumanoidRootPart")
		if TargetHRP and human and PlayerHRP and v ~= script.Parent.Parent then
			if (PlayerHRP.Position - TargetHRP.Position).magnitude < dist then
				dist = (PlayerHRP.Position - TargetHRP.Position).magnitude
				Target = TargetHRP
			end
		end
	end
	return Target
end

wait(0.1)
local TargetHPR = findTarget()
if TargetHPR  then
    if (TargetHPR.Position - PlayerHRP.Position).magnitude < 5 and TargetHPR.Parent.Humanoid.Health > 0 then
		local Hit = Instance.new('Sound',TargetHPR.Parent.Humanoid.Parent.HumanoidRootPart)
		Hit.SoundId = 'rbxassetid://636499038'
		Hit.EmitterSize = 100
		Hit.Volume = .2	
		local att = Instance.new("Attachment")
		att.Name = "att"
		att.Parent = TargetHPR
		local eff = Instance.new("ParticleEmitter")
		eff.Parent = att
		eff.Size = NumberSequence.new(3)
		eff.Texture = "rbxassetid://1084952073"
		eff.LockedToPart = true
		eff.Lifetime = NumberRange.new(0.333)
		eff.Rate = 10
		eff.Speed = NumberRange.new(0)
		local eff2 = Instance.new("ParticleEmitter")
		eff2.Parent = att
		eff2.Size = NumberSequence.new(5)
		eff2.Texture = "rbxassetid://298984512"
		eff2.LockedToPart = true
		eff2.Lifetime = NumberRange.new(0.333)
		eff2.Rate = 10
		eff2.Speed = NumberRange.new(0)
        TargetHPR.Parent.Humanoid:TakeDamage(10)
		local BV = Instance.new("BodyVelocity",TargetHPR)
    	BV.Velocity = script.Parent.Parent.HumanoidRootPart.CFrame.upVector * 20
    	BV.MaxForce = Vector3.new(5000000,999999999,5000000)
    	BV.P = 100 
		Hit:play() 
    	game.Debris:AddItem(BV,.1)
		script.Disabled = true
		wait(.3)
   	 	script:Destroy()
		att:Destroy()
    end
end