Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

my script seems fine but has an error. someone help?(sound doesnt play when i click)

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)

1 answer

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.

6 comments

0

music still doesnt play. got any solution?

0

i am an avid hater of indented code. i make my whole code 1 line so if someone want's to exploit my game they have to strain their eyes trying to read what i've done. some may say its just an excuse for being a bad scripter, however i say it is genius.

0

can u guys answer

0

Are you sure song is pointing to a proper Sound object?

0

Try using local, its a quick way to get around things e.x: local menus = script.Parent.menus:Play()

0

There are a few reasons if the music isn't playing " ITS NOT LOADED! " or " THERE IS NO MUSIC" or, the Volume of the Sound is ZERO, otherwise the script looks fine.

This discussion is preserved as it was. New answers, comments, and votes are closed.