function onClicked() wait(1) script.Parent.GUIAUDIO:play() wait(1) end script.Parent.MouseConnect:connect(onClickedButton)
--This is what i have so far
Assuming the script's parent is a GUI button, you can use MouseButton1Click as the event to trigger a function to occur.
What is MouseButton1Click and how do I use it in my script?
MouseButton1Click is an event in a GUI button that is triggered when the left mouse button is clicked. So by assuming that the script's parent is a GUI button, you can change your script to this:
function onClicked() wait(1) script.Parent.GUIAUDIO:play() wait(1) end script.Parent.MouseButton1Click:connect(onClicked) --The function name should be in the parenthesis (brackets) of the connect method.
But what if your GUI button is a child of the script's parent? Well, all you need to do is change the path on the connection line so that it points to your GUI button.
function onClicked() wait(1) script.Parent.GUIAUDIO:play() wait(1) end script.Parent.BUTTON.MouseButton1Click:connect(onClicked) --Change BUTTON to the name of your GUI button (TextButton or ImageButtons are GUI buttons).
Shortening your script:
While the script I provided above will work, you can shorten your code so that it performs better. You can use an anonymous function to make your script shorter.
script.Parent.MouseButton1Click:connect(function() wait(1) script.Parent.GUIAUDIO:play() wait(1) end)
Read more on anonymous functions here.
MouseConnect
is not a valid event. If you're not sure about properties, events, etc. always be sure to look it up on the Roblox wiki. The proper event for TextButtons is MouseButton1Click
.
Another problem is that the function you try to connect the event to doesn't exist. You named your function onClicked
, but you try to connect the event to a function named onClickedButton
. This will result in an error. You need to do something like:
script.Parent.MouseButton1Click:connect(onClicked)
Since I don't know the hierarchy, it's possible that MouseConnect
is a GUI and you forgot an event entirely. If this is true, you just have to add the event:
script.Parent.MouseConnect.MouseButton1Click:connect(onClicked)