Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Is there any way i can detect when a player uses a tool? My way is not working.

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)

2 comments

0

Maybe try myKnife.Activated?

0

MouseButton1Click is an RBXScriptSignal of GUIButton. You're looking for Button1Down.

1 answer

✓ Accepted answer

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)

2 comments

0

ofc this is locally so anything server related will have to be done with remote events

0

Thanks

This discussion is preserved as it was. New answers, comments, and votes are closed.