Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to script a button?

Asked by
enzdude 10
8 years ago

I'm making a button that will play music when you click it. All I need to know is how to trigger the event when you click the part.

0
This is not a request site. minetrackmania 186 — 8y

2 answers

Log in to vote
2
Answered by 8 years ago

MouseClick checks the part your mouse clicks, to do this > you must insert the object ClickDetector in the part.

Script in part:

local part = script.Parent --Define Parent
local cd = part.ClickDetector --Define ClickDetector
local sound = part.Sound --Define Sound

cd.MouseClick:connect(function() --Connect function to MouseClick
    sound:Play() --Play Sound
end) -- End Function

ClickDetector: http://wiki.roblox.com/index.php?title=API:Class/ClickDetector MouseClick: http://wiki.roblox.com/index.php?title=API:Class/ClickDetector/MouseClick

Ad
Log in to vote
1
Answered by 8 years ago

Though this isn't a request site, I can give you the basics.

When you're making a GUI button, you need to just put a localscript, inside of it. If this is the case of the localscript being inside the TextButton, follow this code.

script.Parent.MouseButton1Click:connect (function(Clicked) -- Button was clicked fully
    print("The button with the name of "..script.Parent.Name.." was clicked.") -- Print a confirmation
end) -- End the function

This code basically functions with putting the text inside the parenthesis, or the ()'s, when clicked by the Left Mouse Button, or MouseButton1. This would be the setting stone to starting the music script. You should note that the Click, and Down functions are different, click means the button was down then up. Down means it was just pushed down.

If this helped you, please click the Accept Answer button, thank you.

Answer this question