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 » Scripting Helpers
Home Search
 

Re: Something happen after you've held the mouse

Previous Thread :: Next Thread 
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
08 Oct 2014 11:27 AM
for a certain amount of time?

How would I do this?
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 11:30 AM
local MouseDown = false

mouse.MouseButton1Down:connect(function()
MouseDown = true
local t = 0
while MouseDown do
t = t+wait()
if t >= 5 then
-- After held for 5 seconds
end
end
end)

mouse.MouseButton1Up:connect(function()
MouseDown = false
end)


Assumes mouse is already defined.
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:31 AM
player = game.Players.LocalPlayer
mouse = player:GetMouse()
local check = false
mouse.Button1Down:connect(function()
check = true
wait(3)
if check == true then
--code
end
end)
mouse.Button1Up:connect(function()
check = false
end)
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:32 AM
Damn, you got a payback ninja :(
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:32 AM
Oh yeah, must be in a localscript.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 11:34 AM
My one stops checking after the mouse is released, rather than after the time is done. Makes it useful for stuff like progress bars or charging animations
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:35 AM
Oh yeah, I forgot to check with a while loop.
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:50 AM
--Just fixed mine:

repeat wait() until game.Players.LocalPlayer
player = game.Players.LocalPlayer
mouse = player:GetMouse()
local num = 0
local check = false
mouse.Button1Down:connect(function()
check = true
while num < 60 and check == true do
wait(0.05)
num = num+1
if num == 60 then
end
end
end)
mouse.Button1Up:connect(function()
num = 0
check = false
end)
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 11:52 AM
repeat wait() until game.Players.LocalPlayer
player = game.Players.LocalPlayer
mouse = player:GetMouse()
local num = 0
local check = false
mouse.Button1Down:connect(function()
check = true
while num < 60 and check == true do
wait(0.05)
num = num+1
if num == 60 then
--code here--
end
end
end)
mouse.Button1Up:connect(function()
num = 0
check = false
end)
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 12:15 PM
Looks a lot messier...
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 01:11 PM
This is not a neatness comp...
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 01:13 PM
Idk
Let's play code golf. Get the expected result in the fewest characters :3
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 01:16 PM
And you never defined mouse.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 01:18 PM
Oh shh. I already said that the code assumes that mouse is already defined.
The real flaw with your code is that wait() can wait longer than it says
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 01:23 PM
In most cases if it waited 3.06 or so seconds instead of 3, the world wouldn't end.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 02:06 PM
Except if he needed it to wait exactly 3 seconds so that it would save the world and it would be like oh my god why did you let it end like that you weirdo that's not how this is supposed to end silly
Report Abuse
IcyFires is not online. IcyFires
Joined: 29 Jun 2013
Total Posts: 5046
08 Oct 2014 02:32 PM
Well it is practically (if not) impossible for it to be exactly x amount seconds, so yours would fail him for 5 seconds too.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Oct 2014 02:55 PM
Shhshhhshhshhsshhhshshshsh
Shh
Shhhhhhh

Shh.
Code golf.
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
08 Oct 2014 02:55 PM
local mouse = game.Players.LocalPlayer:GetMouse() --Not needed if its for a tool as the equipped function returns the mouse

local times, held, holding = {
['1'] = function()
print("The mouse has been held for 1 second")
end;

['5'] = function()
print("The mouse has been held for 5 seconds")
end;

['7.5'] = function()
print("The mouse has been held for 7 and a half seconds")
end;

['8.25'] = function()
print("The mouse has been held for 8.25 seconds")
end;
}, 0, false

mouse.Button1Down:connect(function()
if not holding then
held, holding = 0, true
repeat
if times[tostring(held)] then
times[tostring(held)]()
end
wait(0.25)
held = held + 0.25
until not holding
end
end)

mouse.Button1Up:connect(function()
holding = false
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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