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

how to click a clickdetector while holding a tool?

i am making a streetlight that when you click on it with a wrench the light part gets destroyed but when i tested the game you couldn't touch click detectors with it is there any way i could make it possible

here is the script for the click detector

local clickdetecter = script.Parent:WaitForChild("ClickDetector")
local Team = game:GetService("Teams"):WaitForChild("Construction")
local function onMouseClick(player)
	print('player who clicked is ' .. player.Name)
	if script.Parent.broken.Value == true then
		if player.Team == Team then
			print("player is on construction")
		else
			print("player is not on construction")
		end
	else
		print("light is not broken")
	end
end

clickdetecter.MouseClick:Connect(onMouseClick)

1 answer

✓ Accepted answer
local clickdetecter = script.Parent:WaitForChild("ClickDetector")
local Team = game:GetService("Teams"):WaitForChild("Construction")
local tool = -- make this part of code of where is the tool at (IMPORTANT)
local function onMouseClick(player)
    print('player who clicked is ' .. player.Name)
    if script.Parent.broken.Value == true then
        if player.Team == Team then
	    Tool.Equipped:Connect(function(Mouse) -- If tool is equipped
		Mouse.Button1Down:Connect(function() -- If mouse is down
			script.Parent.MouseHoverEnter:Connect(function() -- If mouse is hovering the part
				            print("player is on construction")
        			else
          				  print("player is not on construction")
        			end
   			 else
        			print("light is not broken")
			end
			end)
		end)
          end)
    end
end

clickdetecter.MouseClick:Connect(onMouseClick)

2 comments

0

Please local the tool at where the Wrench is located at.

0

i tried it it does not work

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