In my code, at the if statement on line 21, it SHOULD be detecting when the mouse is clicked. But in my console, it is not printing "Player has thrown a knife." Even when i told it to when the tool is used. Everything EXCEPT this if statement works. But the weird thing is, i am not getting any errors.
ReplicatedStorage.GiveKnife.OnServerEvent:Connect(function(player) local humanoid = player.Character:FindFirstChildOfClass("Humanoid") if humanoid then humanoid:UnequipTools() print("Knife deselected.") end if player.Backpack:FindFirstChild("Knife") then player.Backpack.Knife:Destroy() print("Knife destroyed") end myKnife = game.ServerStorage.Knife:Clone() myKnife.Parent = player.Backpack myKnife.Name = "Knife" print("Knife created") myKnife.Equipped:Connect(function(mouse) mouse.MouseButton1Click:Connect(function(player) print(player.."has thrown a knife.") end) end) end)
make a localscript in the tool and create ur code there
local tool = script.Parent -- your tool function onActivation() local plr = game.Players.LocalPlayer.DisplayName print(plr.." has thrown a knife.") end tool.Activated:Connect(onActivation)