Remote event firing server 2 times at the same time (But not in studio)

Hello, i was making a projectile that fires when the player clicks the mouse and it worked pretty well, but when i go to the test tab and create a local server and i click the mouse the remote event fires 2 times and i don’t know why.

LocalScript that fires server:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Event1 = ReplicatedStorage.RemoteEvents:WaitForChild("RemoteEvent")

local Mouse = script.Parent.Parent.Parent:GetMouse()

local DB = true

Event1.OnClientEvent:Connect( function()
	
	local MaoPraCimaAnimationInstance = script:WaitForChild("MaoPraCima")
	local MaoPraCimaAnimationTrack = script.Parent.Parent:WaitForChild("Humanoid"):LoadAnimation(MaoPraCimaAnimationInstance)
	
	MaoPraCimaAnimationTrack:Play()
end)

script.Parent.Equipped:Connect( function()
	
	Mouse.Button1Up:Connect( function()
		
		if DB then
			
			DB = false
			
			Event1:FireServer(Mouse.Hit.p, script.Parent.Parent:WaitForChild("HumanoidRootPart"), script.Parent.Parent:WaitForChild("FakeLance"))
			
			wait(5)
			
			DB = true
		end
	end)
end)

Server script that gets activated:

local ServerStorage = game:GetService("ServerStorage")
local TweenService= game:GetService("TweenService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Event1 = ReplicatedStorage.RemoteEvents:WaitForChild("RemoteEvent")

Event1.OnServerEvent:Connect( function(Client, MouseHitp, RootPart, FakeLance)
	
	print("Server fired")
	
	local Lance = ServerStorage:WaitForChild("Lance"):Clone()
	
	Lance.Parent = game.Workspace
	Lance.Position = FakeLance.Position
	Lance.CFrame = CFrame.new(Lance.Position, MouseHitp)
	Lance.Anchored = true
	Lance:WaitForChild("Owner").Value = Client.Name
	
	RootPart.CFrame = CFrame.new(RootPart.Position, MouseHitp)
	RootPart.Anchored = true
	
	local Tween = TweenService:Create(Lance, TweenInfo.new(2, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut), {Size = Vector3.new(0.5, 0.5, 4.5)})
	
	Tween:Play()
	
	wait(2.2)
	
	local BodyVelocity = Instance.new("BodyVelocity")
	
	BodyVelocity.Parent = Lance
	BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
	BodyVelocity.Velocity = CFrame.new(Lance.Position, MouseHitp).LookVector * 100
	
	wait(0.3)

	Lance.Anchored = false
	RootPart.Anchored = false
end)

Output:

If you look at the left of the print you can see that was in the same time, any idea of how to fix this?

Edit: forgot to say that this just happens in the local server, in studio test it doesn’t happens

The more you equip the tool, the more times the event will fire at once. If you look closely in your code, the Button1Up event gets created every time you equip the tool.

Instead of script.Parent.Equipped I would suggest script.Parent.Activated and remove the extra mouse.button1up function.

2 Likes

If this was the case the quantity of fire servers should increase every time i equip the tool, but i tried to do what you said and:

Oh i noticed that this only happens when there is more than 1 player in the server

Nevermind i fixed it, i removed the remote event from replicated storage and put it in the tool, idk why but it worked