Clicking with a tool on a part

How i want my script to work is to add a value after i click on the part with a tool and tool dissapears
But it simply doesn’t work i click on the part with the tool in hand and nothing happens
Heres my script (Heres how i want it to work https://gyazo.com/a4fa6719980824c7be0dc181007469da)

local cauldron = game.Workspace.cauldron
local water = cauldron.Water
local value = cauldron.IngredientValue.Value

local user = game:GetService("Players").LocalPlayer
local mouse = user:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target == water then
	local scroom = user.Backpack:FindFirstChild("Scroom")
	if scroom then
		value = value ..",Scroom"
		scroom:Destroy()
				end
			end
		end)
1 Like

I’m not home right now but there should be a property for your tool and you can switch it on and off so it won’t detect the tool activation, maybe that helps?

I don’t get how that changes anything

One of the easier ways of doing this that most likely isn’t the best solution is by just detecting the players mouse.target.
(Btw im pretty sure that ur variable “value” is useless bc ur saving the value of the value object not the path to the actual object it self (the value variable is not a variable to the value object (that probably made no sense)))

Can you explain it more? I don’t quite get it

Learn about on how to use the players mouse for your script. Once you did that u can detect what the player clicks on and then check the object name (Obviously there are many other ways to detect if its the desired object) to check if you should damage it or not.

Isn’t that what i did though? I got the mouse and made it check for the desired object the problem is not with the mouse but with the tool

Oh my bad, I somehow mixed ur post with someone else’s post (I really dont know how I did it, sorry)

Try this, its the only other solution I can think of.

local cauldron = game.Workspace.cauldron
local water = cauldron.Water
local value = cauldron.IngredientValue

local user = game:GetService("Players").LocalPlayer
local mouse = user:GetMouse()

mouse.Button1Down:Connect(function()
	if mouse.Target == water then
	local scroom = user.Backpack:FindFirstChild("Scroom")
	if scroom then
		value.Value = value.Value ..",Scroom"
		scroom:Destroy()
				end
			end
		end)

nope didnt work same thing happens im clicking with the tool and nothing happens

Try placing prints in a couple of lines.

Also I think you wanna check if the tool is inside the character since u want to destroy it from the players hands while they are holding it?

It detects the input but it doesnt detect the tool while its being held

In the provided gif, there seems to a ClickDetector icon when the player hovers over the cauldron, why can’t you also use clickdetector?

Because held tools are inside the character not the backpack.

1 Like

That was the problem! I was checking the players backpack not the character! It finally works after 2 days of me trying to solve the problem :DDD

I’m glad I was somewhat able to help you :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.