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

How do i make a tool click detector? please help :p

Asked by 4 years ago

Ight i need to know how to make a tool detect a script For example i want it to print "Hello" How would i do so? i know its using :Mouse1Down but i have no idea how to get to the directory help is appreciated, for anyone wondering what its for, i'm trying to make a script for Void script builder 2 and its my first one, anyway help is appreciated, sorry if this is technicly a "request" because i don't have a script but if you wanna help its appreciated :D

0
I'm confused by what you mean. Do you mean when they have a tool equipped and they press down you want it to print hello? NotedAPI 810 — 4y
0
yes, the tool equipped and when you click it prints a message, sorry that wasnt clear mb EllaTheFloofyFox 106 — 4y

3 answers

Log in to vote
1
Answered by
NotedAPI 810 Moderation Voter
4 years ago

Hello, Entity_246!

Sorry for the delay, I was playing a game. Below is a script you can use. All explanation is inside of this script.

local PlayerService = game:GetService("Players")

local Client = PlayerService.LocalPlayer

local Tool = script.Parent

local Equipped = false

function ButtonClick(PlayerMouse) -- the code that will run when they click
    print('Hey')
end

function ToolEquipped(PlayerMouse) -- the code that will run while the tool is equipped
    Equipped = true

    PlayerMouse.Button1Down:Connect(function() -- Button1Down is used when the player click their left mouse button
        if Equipped then
            ButtonClick() -- the function that handles what code to run
        end
    end)
end

function ToolUnEquipped(PlayerMouse)
    Equipped = false
end

Tool.Equipped:Connect(ToolEquipped)
Tool.Unequipped:Connect(ToolUnEquipped)
0
Thank you so much i would upvote but i dont have enough rep :D EllaTheFloofyFox 106 — 4y
Ad
Log in to vote
-1
Answered by 4 years ago

Put a local script inside of the tool with this

local Entity_246MSG = "Your Message Here" ---what is will say

script.Parent:Equipped:Connect(function()
       print(Entity_246MSG) --printing the variable
end)
0
This runs when the tool is Equipped. He wanted it to run something which is print("Hello") when the player clicks their left mouse button. NotedAPI 810 — 4y
Log in to vote
-1
Answered by 4 years ago

Okay, let's say you are making a sword and you want it to print "Hello World!" when activated.

You'd write this:

local tool = script.Parent

tool.Activated:connect(function()
    print("Hello World!")
end)

Please let me know if that does not work.

Answer this question