On the contrary of posts I've posted before on this website this actually is an informational question. but, instead of it being a question it is actually a way for anyone who would be asking this question to figure out the answer. I asked this question to numerous people and got Completely
different answers every time. I've finally after a day and a half of asking have found out the correct solution.
As that was kinda annoying i'm going to help people out who need the same answer themselves.
The correct solution is after finding the mouse you connect a function that plays when the player holds down the whatever button
here is an example of this code -
lua
mouse.Button1Down:Connect(function()
now after this function under it you put whatever code would run whilst holding the left mouse button down in this case I will be making a brick when u hold down the Left button
here is an example of that -
lua
mouse.Button1Down:Connect(function()
local part = Instance.new("Part")
end)
Now that you've done that u need to make a function so that the player can release from this otherwise they would just be stuck lol. This will find if the mouse button is up most likely you'd want to remove or do the opposite of whatever you did on hold. Because we closed off the function completely and it was a local function we'll have to index the part directly.
here is an example of that -
```lua
mouse.Button1Down:Connect(function()
local part = Instance.new("Part")
end)
mouse.Button1Up:Connect(function()
Now that we've done that we can now add in code under that *in this case I will be removing the brick that was there before*
lua
mouse.Button1Up:Connect(function()
part:Destroy()
end)
The entire script should look like this **without indexing the player and mouse of course**
lua
mouse.Button1Down:Connect(function()
local part = Instance.new("Part")
end)
mouse.Button1Up:Connect(function() local part = workspace.Part part:Destroy() end) ``` That's all folks -Hope this helped you out lol also this is my first time doing this so please tell me anything I did wrong :D
now, I can just be a really bad person by just saying to go use
Mouse.Button1Down()
Nope!... I'm not gonna leave you fellow scripter like that. I remember I had made a minigun back then and it requires the same thing
first you need a bool - Variable to see if the player is pushing the left mouse button down. Here is how it will work..
local play = game.Players.LocalPlayer--Get the Local Player local mouse = play:GetMouse()---And Get the mouse too! :D local down = false--- a variable to tell is the player is holding down the mouse button... local used = false--- to tell if the player used the item or tool local cooldown = 3---- 3 Seconds mouse.Button1Down:Connect(function()--Decare the MouseDown Function if not used then------- if used == false then... used = true----- make used true down = true--- make down true while true do--- a while loop wait(.5)---- wait every .5 seconds (Well.. you can change this to what ever increment in time you want... the lower the faster, the higher the slower......) if not down then-- if down = false then break-----Break the loop and just end it their end print("The Left Mouse Button has Been Held Down!")----this will print every 5 seconds when the player has theei left mouse button down end used = true---make use = true when the left mouse button has been lifted... or when the loop has been broken... wait(cooldown)---wait that cooldown...... used = false--and make the use value false, scince you are done using the tool or item end end) mouse.Button1Up:Connect(function()---declear the button up function down = false--- and all this will do will make make down = false end)
And that's how you make a button down function. :)
---T40 (Accept this answer if you like it :D)