so theres a menu gui, and this script is inside the play button.
a sound is playing.
how can I make it so if I click, the r2dm sound stops and the other sound plays?
if you want to help me, make sure the sound stops and r2dm plays if the player dies. thanks.
local song = script.Parent:WaitForChild("Sound") --normal song local menus = script.Parent:WaitForChild("R2DM") --menu song menus:Play() function onClicked(GUI) menus:Stop() song:Play() end script.Parent.MouseButton1Click:connect(OnClicked)
Your script is correct, however on line 10 you connected OnClicked
, starting with a capital, but you defined your function as onClicked
, starting with a lowercase. Lua is case-sensitive.
Also, use Connect
instead of connect
because the latter is deprecated.
Final note, I highly recommend indenting your code, it makes it much easier for you and everyone else to read.
By indenting I mean having a tab space in front of every line that inside a child block:
-- NON INDENTED function onClicked(GUI) menus:Stop() song:Play() end -- INDENTED function onClicked(GUI) menus:Stop() song:Play() end
The indented block is much easier to read and understand.