Basically my goal here is when the player moves the passport to the sensorpart, and holds it there for 3 seconds, I want it to then run something but only if the mouse.target has been on the defined part for a total of 3 seconds without taking it off.
Thanks!
if mouse.Target == PassportSensor then
print("Hit me please)
-- Does Stuff
end
Hello, I do not think It Is possible without a few functions, I do not think there Is anything about how long mouse.target has been on a part, the script I will send may not be the most effective or working, It Is just a way I think It can be achieved.
local passportSensor = workspace.PassportOrsomethingidk
local timer = 0
local isOnSensor = false
local function onConditionMet()
print("Condition met: Mouse has been on the PassportSensor for 3 seconds")
-- Do stuff here
end
local function resetTimer()
timer = 0
isOnSensor = false
end
local function onMouseEnter(target)
if target == passportSensor then
isOnSensor = true
timer = 0
end
end
local function onMouseLeave(target)
if target == passportSensor then
resetTimer()
end
end
while true do
wait(1)
if isOnSensor then
timer = timer + 1
if timer >= 3 then
onConditionMet()
resetTimer()
end
end
end
You need to connect these functions to the appropriate mouse event listeners in your game For example: mouse.Move:Connect(onMouseMove), You will need to figure out the best way to track mouse entry and exit in your game’s context