How do you make something play after holding down a MouseButton and releasing it?
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 -
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 -
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 -
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
mouse.Button1Up:Connect(function()
part:Destroy()
end)
The entire script should look like this without indexing the player and mouse of course
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

5 comments
I don't think that would work. The loop should be a "while down do" loop.
roblox, copy, paste , and test the script your self, within your local script before you criticize others...
I had Test the script myself.
Ye because that's so much easier than just using two built in functions
I mean thanks for showing how my way is actually better efficiently though