ClickDetector doesn't work with tool equipped?

I’m making a frame that gets opened when you click on a part which requires to have a tool equipped. The problem is that it does print (“No tools equipped!”) but doesn’t open the frame I equip my tool.

I tried using the Mouse Target function to detect if the mouse is hovering the part, however it does not seem to work either.

-- Variables

local OpenPart = workspace:WaitForChild("Map"):WaitForChild("UpgradesShop"):WaitForChild("OpenPart")

local Gui = script.Parent.Parent
local Frame = Gui:WaitForChild("Frame")
local AreYouSureFrame = Gui:WaitForChild("AreYouSure")

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

local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()

---------------------------------------------------

-- Code

Mouse.Button1Down:Connect(function()
	
	local NoToolsEquippedNotification = PlayerGui:WaitForChild("Notifications"):WaitForChild("NoToolsEquipped")
	
	if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == false and Mouse.Target == OpenPart then
		Frame.Visible = true
		AreYouSureFrame.Visible = false
	end
	
	if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == true and Mouse.Target == OpenPart then
		Frame.Visible = false
		AreYouSureFrame.Visible = false
	end
	
	if Character:FindFirstChildWhichIsA("Tool") == nil and Mouse.Target == OpenPart then
		NoToolsEquippedNotification.Visible = true
		wait(1)
		NoToolsEquippedNotification.Visible = false
	end
	
end)

Thanks for your help!

1 Like

Wait so the part has a click detector in it?

1 Like

First of put mouse.Target into a variable, i dont k ow why people keep directly referencing mouse.Target

1 Like

Yes.

I tried with the ClickDetector, which didn’t work.
Then I tried Mouse.Target, which also didn’t work.

Im on my phone so i cant type the code for you but putting mouse.Target in a variable should propably fix ut

1 Like

Can you wait like 30 minutes im at gym, i can do it when i get home. You can have a boolean true or false when ever the player equips tool and connect it to tool.Equiped event

1 Like

Of course I can wait. You aren’t rushed at all. Thanks!

Unfortunately I just tried but it did not fix the problem : (

Im home let me eat then do it for u

1 Like

This is an intended behavior of ClickDetectors.

3 Likes

But how can I prevent this from happening?

-- Variables

local OpenPart = workspace:WaitForChild("Map"):WaitForChild("UpgradesShop"):WaitForChild("OpenPart")

local Gui = script.Parent.Parent
local Frame = Gui:WaitForChild("Frame")
local AreYouSureFrame = Gui:WaitForChild("AreYouSure")

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

local PlayerGui = Player.PlayerGui
local Character = Player.Character or Player.CharacterAdded:Wait()

---------------------------------------------------

-- Code

Mouse.Button1Down:Connect(function()
    local target = Mouse.Target
	
	local NoToolsEquippedNotification = PlayerGui:WaitForChild("Notifications"):WaitForChild("NoToolsEquipped")
	
	if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == false and target== OpenPart then
		Frame.Visible = true
		AreYouSureFrame.Visible = false
        return
	end
	
	if Character:FindFirstChildWhichIsA("Tool") ~= nil and Frame.Visible == true and target == OpenPart then
		Frame.Visible = false
		AreYouSureFrame.Visible = false
        return
	end
	
	if Character:FindFirstChildWhichIsA("Tool") == nil and Mouse.Target == OpenPart then
		NoToolsEquippedNotification.Visible = true
		wait(1)
		NoToolsEquippedNotification.Visible = false
	end
	
end)

the reason was once the frame was visible, it then became unvisible again because the next if statement ran. you didnt break the function with a return statement

3 Likes