[SOLVED] Click detector doesn't fire MouseHoverEnter or MouseHoverLeave when a tool is equiped

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear! MouseHoverEnter and MouseHoverEnter to fire when a tool is equiped

  2. What is the issue? Include screenshots / videos if possible! MouseHoverEnter and MouseHoverLeave do not fire when a tool is equiped

https://gyazo.com/8e921f2c910b604d7400d50e3476e3e7

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub? I have tried disabling the script inside the tool

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

– inside starterpack

local player = game:GetService("Players").LocalPlayer
local Mouse = player:GetMouse()
local TweenService = game:GetService("TweenService")

local RS = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local Assets = RS:WaitForChild("Assets")

local Ui = Assets:WaitForChild("UI")
local Sound = Assets:WaitForChild("Sound")
local Remotes = Assets:WaitForChild("Remotes")

local MainModule = require(game.ReplicatedStorage.Main)

for i, v in pairs(workspace:GetDescendants()) do
	if v:IsA("ClickDetector") then
		v.MouseHoverEnter:Connect(function()
			local Highlight = script:WaitForChild("Highlight"):Clone()
			Highlight.Parent = v.Parent
			Highlight.OutlineTransparency = 1
			TweenService:Create(Highlight, TweenInfo.new(0.15, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {OutlineTransparency = 0}):Play()
		end)
		
		v.MouseHoverLeave:Connect(function()
			v.Parent.Highlight:Destroy()
		end)
		
		if v.Parent.Name == "Door" then
			v.MouseClick:Connect(function()
				MainModule.Door(v.Parent.Parent, Mouse.TargetSurface)
			end)
		end
		
		if v.Parent.Parent.Name == "NPC" and v.Parent.Parent.Parent == workspace then
			v.MouseClick:Connect(function()
				Remotes.NPC:FireServer(v.Parent.Name, "Start")
			end)
		end
		
	end
end

– inside tool

local RS = game:GetService("ReplicatedStorage")
local Debris = game:GetService("Debris")
local Assets = RS:WaitForChild("Assets")
local player = game:GetService("Players").LocalPlayer
local TweenService = game:GetService("TweenService")

local Ui = Assets:WaitForChild("UI")
local Sound = Assets:WaitForChild("Sound")
local Remotes = Assets:WaitForChild("Remotes")
local Items = Assets:WaitForChild("Items")

local Shadows = script.Parent.Shadows

script.Parent.Equipped:Connect(function()
	Text = Ui:WaitForChild("ShadowCount"):Clone()
	Text.Parent = player.PlayerGui.Hud
	Text.Text = "Shadows "..Shadows.Value.."/10"
	Shadows.Changed:Connect(function()
		Text.Text = "Shadows "..Shadows.Value.."/10"
	end)
end)

script.Parent.Unequipped:Connect(function()
	Text:Destroy()
end)


Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

clickdetectors are disabled when a tool is equipped. if you wanted to accomplish this you could check if the player’s cursor is on a specific part

2 Likes

is there any way you can enable clickdetectors when a tool is equipped

1 Like

i found this solution in a thread with a similar problem

2 Likes

you can do this by making a ClickDetecter using scripts using and mouse.target when the player clicks first put this local script in StarterPlayerScripts.

1 Like

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local click = false
local function IfClick()
local succes, errormessage = pcall(function()
local hit = mouse.Target
if hit ~= nil then – if hit does not = nil
if player:DistanceFromCharacter(hit.Position) < 15 then – hot far the player is from the object its clicking
local event = – the event to fire the server script
event:FireServer()
click = true
end
end
end)
if not succes then
warn(errormessage)
end
end

mouse.Button1Down:Connect(IfClick)

1 Like

next this in your script:

local clickedEvent = – Event

function toolEquipped(character)
for _, child in pairs(character:GetChildren()) do
if child:IsA(“Tool”) then
if child.Name == “Tool name” then
return true
end
end
end
return false
end

local function Clicked(player)
–code here
end

clickedEvent.OnServerEvent:Connect(function(plr)
local bool = toolEquipped(plr.Character)
if bool == true then
Clicked(plr)
end
end)

1 Like