ClickDetector Tools

I’m trying to make a Simulator. everythings been going good so far but I can’t seem to find a work around for letting players only use click detectors when they have their tools equipped. Right now it won’t let them use them if they have their tools equipped. But My goal is to make it so they can only use the click detectors with their tools equipped. If someone could link me to a wiki that explains more on this that would be great! any suggestions are much appreciated.

Kind Regards
TheTimeDefender

11 Likes

Click Detectors by default can’t be used when you have a tool equipped, so you must create a custom click detector.

Tool.Activated:Connect(function() -- listens for clicks; alternatively you could use Mouse.Button1Down
    if Tool.Equipped then --checks if tool is equipped
        if Mouse.Target == Button then --checks if mouse is over a button
            --code
        end
    end
end

References:

7 Likes

I seem to be having troubles but thanks anyways! I’ll probably pay someone to make it so that Click Detectors are only activated when they click on them with a tool equipped.

So that I can still use click detectors.

As I’ve stated, you cannot use click detectors and tools at the same time. You could still use click detectors with the method I have provided, you just need to add and revise some parts of/to it.

For instance, if you want the max activation to still work, you could use this:

if (Tool.Handle.Position - Mouse.Target.Position).Magnitude <= Button.ClickDetector.MaxActivationDistance then
    --code
end

You won’t be able to use ClickDetector.MouseClick because this event won’t fire when a tool is equipped. ClickDetectors were designed like this because it will interfere with Tool.Activated.

Tool.Activated:Connect(function() --listens for clicks
    if Tool.Equipped then --checks if tool is equipped
        if Mouse.Target and Mouse.Target:FindFirstChild("ClickDetector") then --checks if mouse is over a button
            if (Tool.Handle.Position - Mouse.Target.Position).Magnitude <= Mouse.Target.ClickDetector.MaxActivationDistance then --checks if player is within max distance
                --run code
            end
        end
    end
end

If you are having trouble, don’t hesitate to ask me :slight_smile:, my inbox is open, it’s the purpose of the devforum anyway.

If you want to hire someone to do the job, then go ahead, but if I were you, I’d give it a little try :slight_smile: it’s simpler than you think and that’s how most developers learn how to code.

20 Likes

At this point, you might as well not use ClickDetectors in the first place. Given that ClickDetectors and tools aren’t meant to be used together, you might as well embed the check logic in the tool itself with a way to fetch an external maximum activation range.

Realistically you could make both work at the same time but that’d be a pretty weird solution and might lead into various efficiency and practice traps early in.

5 Likes

I didn’t realize someone replied until now I’ll give it a shot thank you!

1 Like

Local script.

I would put it in the tool because it makes more sense.

Yes e.g. local Tool = wherever your tool is

1 Like