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
 

Making tool work when button1 is held

Previous Thread :: Next Thread 
tinarg is not online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
04 Jun 2014 06:39 PM
I'm making a tool version of the move tool... it works great except for the fact that you gotta click constantly to keep moving something. How would I make it in which it will keep going as long as the button is held down? Here's the code:

local Mouse = game.Players.LocalPlayer:GetMouse()

function bdown()
if Mouse.Target.Locked == false then
Mouse.Target.Position = Mouse.Hit.p
end
end
function sel(m)
m.Button1Down:connect(bdown)
end
script.Parent.Equipped:connect(sel)
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
04 Jun 2014 06:47 PM
local Mouse = game.Players.LocalPlayer:GetMouse()
local Down = false

function bdown()
if Mouse.Target.Locked == false then
Mouse.Target.Position = Mouse.Hit.p
end
end
function sel(m)
m.Button1Down:connect(function() if Down return end Down = true
while Down do bdown() wait() end end
m.Button1Up:connect(function() Down = false end)
end
script.Parent.Equipped:connect(sel)
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
04 Jun 2014 06:51 PM
You would use the button1down event, and the button1up event, and the mouse's move event.

m=game.Players.LocalPlayer:GetMouse();
variable=false;

m.Button1Down:connect(function()
target = m.Target
if target then
variable = true
m.Move:connect(function()
if variable == true then
target.CFrame = CFrame.new(m.hit.X,m.hit.Y+(target.Size.Y/2),m.hit.Z)
end
end)
end
m.Button1Up:connect(function()
variable = false
end)
end)
Report Abuse
tinarg is not online. tinarg
Joined: 18 Jun 2010
Total Posts: 4925
04 Jun 2014 07:00 PM
It works now... but how would I make it always welded to the floor? I'm trying to make a clone of the classic move tool, but in tool form.
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