Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Any way to automatically press buttons?

Asked by 5 years ago

I am trying to make a script and i want to know if there is any way to execute a script to automatically trigger ClickDetector without manually clicking it?

0
Why would you need to do such a thing? The_Pr0fessor 595 — 5y

3 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

What you could do is utilize the Mouse.Target Component and put it in a while loop or something I don't know but you could do...

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Object = -- the object with the ClickDetector in it

while wait() do
    if Mouse.Target == Object then
        --Fire an Event or Whatever Your trying to do
    else
        return
    end
end

https://developer.roblox.com/api-reference/property/Mouse/Target

https://developer.roblox.com/api-reference/class/RemoteEvent

Ad
Log in to vote
0
Answered by 5 years ago
function Clicked()
    -- Do stuff here
end



ClickDetector.MouseClick:connect(Clicked) -- When the player clicks the block the Clicked() function activates.

Clicked() -- This will also activate the Clicked() function without the need of a player clicking the block.
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

ClickDetectors have an event named MouseHoverEnter. This event fires when the player's Mouse enters the area of the ClickDetector. Like MouseClick, it passes a player as its argument to the first parameter in a function. Unlike MouseClick (and hence its name), it does not rely on manually clicking the ClickDetector but rather on manually entering the area of the ClickDetector where it detects the player's mouse. By using this event, you can "imitate" a click:

local CanActivate = true; --// A debounce to prevent the function from repeatedly running when the event fires
--// Other variables...
script.Parent.ClickDetector.MouseHoverEnter:Connect(function(player);
    if CanActivate then
        CanActivate = false;
        --// Do something here
        wait(3); --// Waiting time; this can be changed to a waiting time of your choice
        CanActivate = true;
    end
end)

Answer this question