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

How to check what a tool has clicked?

player = game.Players.LocalPlayer
tool = script.Parent
handle = tool.Handle

function onClicked()
	handle.BrickColor = BrickColor.new("Bright red")
end

tool.Equipped:connect(function(mouse)
	mouse.Button1Down:connect(onClicked)
end)

I have this so when I played clicks it changes the color of the handle, but how can I make it check what the player has clicked, like if onClicked.Name == "Dirt" then print("You clicked on dirt")

1 answer

✓ Accepted answer

Try putting a ClickDetector in anything that can be clicked, and include a script in it. Make the script have the following:

script.Parent.ClickDetector.MouseClick:connect(function()
	print("You clicked on " .. script.Parent.Name.. "!")
end)

2 comments

0

That would not work because clicking ClickDetectors with a tool selected does not work.

0

^ yeah and it must be with a tool, cause im making a game kinda like minecraft, but you need a tool to mine the block

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