How to click a part when holding a tool?

mouse.icon = CD.icon-- your icon

“mouse” is undefined, change it to “Mouse” instead

1 Like

it wont let you click with the gun equipped because when your gun is equipped and you click it is supposed to shoot so that’s why you can’t click click detectors

try what he did!!!

but if you use mouse.Target it just might work

1 Like

This is the localscript inside of the tool. It doesn’t even go through Part A.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent

Tool.Activated:Connect(function()
	local Target = Mouse.Target
	print("Part A")
	if Target:FindFirstChildWhichIsA("ClickDetector") then 
		local CD = Target:FindFirstChildWhichIsA("ClickDetector")
		print("Part B")
		Mouse.icon = CD.icon
		local Health = game.Workspace.SpecOps.Ten.Health
		Health.Value = Health.Value - 10
		Player.Spec_Ops_Infected.Score.Value = Player.Spec_Ops_Infected.Score.Value + 10
	end
end)
1 Like

try making the *Target “T” to lower case

It didn’t work.
https://gyazo.com/1c031d3ed431cbf57f233559930c14d2

1 Like

Try capitalizing the i in that line.

did it work???

That didn’t work., it seems to be before the first print statement.

how about you skip the icon part delete all the icon parts or just re-copy my script

I fixed it!

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Tool = script.Parent
print("This worked")
Tool.Activated:Connect(function()
	local Target = Mouse.target
	print("Part A")
	if Target:FindFirstChildWhichIsA("ClickDetector") then 
		local CD = Target:FindFirstChildWhichIsA("ClickDetector")
		print("Part B")
		local Health = game.Workspace.SpecOps.Ten.Health
		Health.Value = Health.Value - 10
		Player.Spec_Ops_Infected.Score.Value = Player.Spec_Ops_Infected.Score.Value + 10
	end
end)


3 Likes

i am to lazy to see what changed what was the problem???

local plr = game.Players.LocalPlayer
local Mouse = plr:GetMouse()

Mouse.Button1Down:connect(function()
if Mouse.Target == workspace.Part then
print(“f”)
end
end)

Sorry if this doesn’t work I didn’t write this in roblox studio this should somewhat work. The Capilization could be wrong.

he already solved his problem it

Oh I didn’t saw that because he didn’t mark it as solved Sorry.

1 Like

so it was the lower case “t” in target?

I think so.
https://gyazo.com/ab998e65a24ebe8d9511b0f91a99d0b1

1 Like

what was the problem please answer

can you please tell us the answer