I'm trying to make a gun, but can't seem how to make it automatic. This is my trash script:
while true do
script.Parent:Activate()
end
All the variables/raycasting is dealt with, and this is just really annoying! Is anyone able to help?
I'm trying to make a gun, but can't seem how to make it automatic. This is my trash script:
while true do
script.Parent:Activate()
end
All the variables/raycasting is dealt with, and this is just really annoying! Is anyone able to help?
Try this: Note had a little fun with the printout... you can delete them if you like lol
local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local ToolActive = false
local MouseHeldDown = false
Tool.Activated:connect(function()
print("Woot! we\'ve been Activated!!!! YAAYY!!!")
Mouse.Button1Down:Connect(function()
MouseHeldDown = true
end)
Mouse.Button1Up:Connect(function()
MouseHeldDown = false
end)
end)
Tool.Deactivated:connect(function()
print("Nooooo! we've been deactivated!..... *cries*")
MouseHeldDown = false
end)
Tool.Equipped:connect(function()
print("WOH weve been selected o.0!!")
end)
Tool.Unequipped:Connect(function()
print("Noooo!... I only farted you dont have to run away... oh god help mez pls!")
end)
local oldMouseHeld = nil
while true do
--// only print out the change in mouse press!
if(oldMouseHeld ~= MouseHeldDown) then
print("MouseHeldDown is [",MouseHeldDown,"]")
oldMouseHeld = MouseHeldDown
end
wait()
end
Just a little example on how to handle mouse held down. you can still activate your gun but check to see if the new varible MouseHeldDown is true or not before doing stuff!.
Hope this helps!
oh! just encase, this in a Local script NOT server side!
Why are connecting events inside events
and i also see varying usage of Connect and connect
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
Just detect whether the mouse is down or not and fire if it is