For some reason this prints two times instead of one?

For some weird reason, “stuff happens” prints two times whenever I press a block. Any Idea how I could fix it?

local player = game.Players.LocalPlayer
local tool = script.Parent
Set = game.ReplicatedStorage.RemoteEvents.SetEvent
local Target = game.Workspace.Block

Set.OnServerEvent:Connect(function(Player, Target, Tool)
	if Target.Name == "Block" and Tool.Parent == Player.Character then
		print ("stuff happens") --Instead of printing, add whatever function here you like so the tool can do something when you click the block
	end
end)

Thanks

1 Like

Can you show the code that fires the remote event? Without that I cannot help you.

Ok. Here it is

local Tool = script.Parent --make sure this is a Tool object
Set = game.ReplicatedStorage.RemoteEvents.SetEvent
local Target = game.Workspace.Block

Tool.Equipped:Connect(function(Mouse)
	Mouse.Button1Down:Connect(function()
		Set:FireServer(Target, Tool)
	end)
end)

Tool.Activated:Connect(function()
    Set:FireServer(Target, Tool)
end) 

When you click both the Mouse.Button1Down and Tool.Activated events are fired.

1 Like

That is because you have two functions calling the event. You can either remove the top or bottom function. Although I would remove the top function since the bottom is more simple and does the same job!

1 Like

So, if I remove one will it still work?

1 Like

Yes it will remove the first function.

1 Like

If you need to use the player Mouse for anything else keep the first one.