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

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

Asked by
worklok -24
5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago

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.

0
music still doesnt play. got any solution? worklok -24 — 5y
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. Launderer 343 — 5y
0
can u guys answer worklok -24 — 5y
0
Are you sure `song` is pointing to a proper Sound object? chomboghai 2044 — 5y
View all comments (2 more)
0
Try using local, its a quick way to get around things e.x: local menus = script.Parent.menus:Play() User#22722 20 — 5y
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. AIphanium 124 — 5y
Ad

Answer this question