I have a combat system in my game where the player will do a fist attack when they have no tools equipped and they click the left mouse button through UserInputService:InputBegan. NPCs and items that you can pick up in my game use clickdetectors, and because of the combat system the player will always punch whenever they talk to an NPC or pick up an item. How can I prevent this?
There is a way where you can detect if the player hovers over a clickdetector.
ClickDetector.MouseHoverEnter
(ClickDetector.MouseHoverEnter)
Or you can use an if statement and check if the part/model has a clickdetector and don’t punch when you are hovering on it.
1 Like
Try something like this:
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
canClick = true
local function checkForHover()
if mouse.Target:IsA("ClickDetector") or mouse.Target:FindFirstChildWhichIsA("ClickDetector")
canClick = false
return
end
canClick = true
end
mouse.Button1Down:Connect(function()
checkForHover()
if canClick then
— Run
end
end)