generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: [HELP] Best way to use Button1Down event?

Previous Thread :: Next Thread 
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
26 Jan 2017 11:50 AM
Basically what im trying to do is differentiate between when the mouse is held down and when it is clicked. Inside the renderstepped function I detect if the mouse is being held down, but it seems kind of a dodgy way of doing it, also alot of problems do occur, e.g when the player is spamming mouseclick.

So does anyone have better ideas of doing it. Script:


spawn(function()
mouse.Button1Up:connect(unprinted) <-sets disabled to true
mouse.Button1Down:connect(printed) <-sets disabled to false
end)


game:GetService("RunService").RenderStepped:connect(function()
if start == false then
if disabled == false and equip == true then
local anim = tool:FindFirstChild("ThrowCharge")
wait(.4)
if disabled == false and equip == true then
wait(.4)
if disabled == false and equip == true then
wait(.4)
if disabled == false and equip == true then
--code
end
end
end
end
end
end)
Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
26 Jan 2017 11:54 AM
why are you using spawn for events? events do NOT pause the script


Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444
Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
26 Jan 2017 12:01 PM
Okay removed it, so is there a better way?
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
26 Jan 2017 12:06 PM
player = game.Players.LocalPlayer
mouse = player:GetMouse()
status = "up"

mouse.Button1Down:connect(function()
status = "down"
while status == "down" do
print("button 1 is being held down")
wait()
end
end)

mouse.Button1Up:connect(function()
status = "up"
print("mouse was released")
end)


Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
26 Jan 2017 12:09 PM
Tried that, but it wont work for what Im trying to do...
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
26 Jan 2017 12:19 PM
Why not just use Button1Click?


Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
26 Jan 2017 12:24 PM
local tool = script.Parent
local anim = tool:WaitForChild('ThrowCharge')
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local equipped,down

mouse.Button1Down:connect(function()
down = true
while equipped and down do
--do stuff
wait()
end
end)

mouse.Button1Up:connect(function()
down = false
end)

tool.Equipped:connect(function()
equipped = true
end)

tool.Unequipped:connect(function()
equipped = false
end)





Report Abuse
NeonDolphin37 is not online. NeonDolphin37
Joined: 24 Dec 2013
Total Posts: 895
26 Jan 2017 12:24 PM
local hasReleased = false
local isDrag = false
mouse.Button1Down:connect(function()
isDrag = false
hasReleased = false
wait(.5)
if not hasReleased then
isDrag = true
while not hasReleased do
--code here
wait()
end
end
end)

mouse.Button1Up:connect(function()
hasReleased = true
end)
Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
26 Jan 2017 12:24 PM
No such function of mouse :P

http://wiki.roblox.com/index.php?title=API:Class/Mouse
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
26 Jan 2017 12:26 PM
Haha I guess you're right


Report Abuse
KritikalGunzz is not online. KritikalGunzz
Joined: 10 Nov 2013
Total Posts: 1633
26 Jan 2017 12:26 PM
Nvm ill try and get it to work with a while loop
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
26 Jan 2017 12:28 PM
Use any of the three methods we posted above, they're all basically the same.


Report Abuse
SenseiWarrior is online. SenseiWarrior
Joined: 09 Apr 2011
Total Posts: 12140
26 Jan 2017 04:59 PM
button1click doesnt exist because its intended for guis only
button1click basically makes sure u pressed on the button and released on the button


Downgrading STF // https://www.roblox.com/Trade/TradeWindow.aspx?TradePartnerID=6163444
Report Abuse
Soybeen is not online. Soybeen
Joined: 17 Feb 2010
Total Posts: 21462
26 Jan 2017 05:18 PM
yeah after 4s of looking at the wiki I gathered that


Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image