tool = script.Parent Handle = tool.Handle if tool.Activated then Handle.Touched:Connect(function(Touch) if Touch then L = Touch.Parent:FindFirstChild('Humanoid') if L then L:TakeDamage(69) end end end) end
aight so im trying to make a weopon where if you click and it touches a person it does damage but there seems to be no way for me to press and damage keep in mind i dont wanna damage a person if I don't click
Activated is an event. You can :Connect()
to it,* but it is not a boolean. (This code will always run If you want to keep track of whether it's activated or not, you can set a value whenever it's Activated
or Deactivated
.
* You just connect to an event by doing event:Connect(function)
, so an example would be
local myFunction(thingThatGotItsAncestryChanged, newAncestor) print("how'd " .. thingThatGotItsAncestryChanged .. " get into " .. newAncestor) end local x = game.AncestryChanged:Connect(myFunction)
You can find more information on events here, the wiki has some good information on them. ("Discussion" is the important part since you don't need to disconnect anything, just connect.)
Edit: Another thing to note is that when you connect a function to a connection, it will always be connected unless directly disconnected (or the object of the event is destroyed since there's not going to be anything firing the event). This means that your current code will always check for when the handle is touched, even if the mouse button is no longer being held down. You can only stop an event by :Disconnect
ing it, meaning you should check inside the connected Touched
function whether your mouse button is being held or not. (Preferable to do this by checking the variable that you're changing whenever a tool is activated or deactivated; disconnecting and reconnecting whenever the mouse button is pressed and unpressed is probably not very efficient.)
Edit 2: Edited the edit for clarification.