You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? I want to print one time ONLY if the mouse hovers into a part and be able to print again when the mouse isnt hovering the part and hovers again (in the output should appear: Testing (x2))
What is the issue? When the mouse enters the part theres a lot of prints including when the mouse leaves the part
What solutions have you tried so far? nothing for now
btw the script that im using is:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ToolName = "Tool"
local UserInputService = game:GetService("UserInputService")
UserInputService.InputChanged:Connect(function(input, engine_processed)
if engine_processed then
return
end
if input.UserInputType == Enum.UserInputType.MouseMovement then
if Mouse.Target:IsA("Part") and Mouse.Target:FindFirstChild("ClickDetector") and Player.Character:FindFirstChild(ToolName) then
print("Player's Mouse is Over a part which has a Click detector and Tool equipped.")
end
end
end)
Add a debounce (a value meant to control if your code should be running):
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ToolName = "Tool"
local UserInputService = game:GetService("UserInputService")
local debounce = true --<<
UserInputService.InputChanged:Connect(function(input, engine_processed)
if engine_processed then
return
end
if input.UserInputType == Enum.UserInputType.MouseMovement then
if Mouse.Target:IsA("Part") and Mouse.Target:FindFirstChild("ClickDetector") and Player.Character:FindFirstChild(ToolName) then
if debounce == true then -- the debounce will decide if not to run this bit of code
print("Player's Mouse is Over a part which has a Click detector and Tool equipped.")
debounce = false -- disables the script
--this part is only if you want your message to be printed out again after a certain time (used 5s as an example)
wait(5)
debounce = true -- re-enables the script
end
end
end
end)
This will only toggle the printing, to disable the event you’ll have to disconnect it:
elseif input.UserInputType == Enum.UserInputType.MouseIdle then
if Mouse.Target:IsA(“Part”) then
debounce = false
elseif Mouse.Target ~= workspace.Part then
debounce = true