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

How do I fix the "Play Sound" button in my admin panel? and the rest- too long

Asked by 4 years ago

The issue is, is that, when I try to click the "Play Sound" button, (even on like... 1 hour long sounds) it just immediately changes the text to "Stop Sound" and another microsecond later it changes to "Play Sound" without playing the audio. The things I tried is inside the code block below.

01local Module = require(game.StarterGui.eText)
02local btn = script.Parent.Parent.BtnPlay
03local input = script.Parent.Parent.Input
04local sound = workspace.Sound
05local playing = false
06 
07btn.MouseButton1Click:Connect(function()
08    if playing == false then -- (<-- Which is this one) I tried to make it easier for the script to understand but didn't work, the previous one was
09                 -- "if not playing then"
10        sound.SoundId = "rbxassetid://" .. input.Text
11        sound:Play()
12 
13        Module.ApplyText(btn, "Stop Sound")
14        playing = true
15        wait(sound.TimeLength) -- If I put it to 8 seconds, the sound will play for 8 seconds but
View all 31 lines...
0
ok so... in local sound do local sound = game.Workspace.Sound Mrpolarbear2games 55 — 4y
0
not sure what the point of sound.SoundId = "" is because when you stop the sound it wont play and when you enter a new one it will automatically clear it Mrpolarbear2games 55 — 4y
0
"workspace" is the same as "game.Workspace" but shorter User#39895 0 — 4y
0
Just replying to your "not sure what the point of sound.SoundId = "" is ... ": Ohhh ok! User#39895 0 — 4y

2 answers

Log in to vote
0
Answered by
imKirda 4491 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

i could be wrong but it could be because the sound is not yet loaded when you index it's TimeLength (If it's not loaded it will return 0), that's because roblox must first access it's servers and get product info of the sound and then only configure the sound. You have 2 solutions here, GetPropertyChangedSignal or Sound.Ended.

GetPropertyChangedSignal

This is a signal that fires when given property of instance changes, in your case you can wait until the sound's length is not 0:

01...
02sound.SoundId = "rbxassetid://" .. input.Text
03sound:Play()
04 
05Module.ApplyText(btn, "Stop Sound")
06playing = true
07 
08Sound:GetPropertyChangedSignal('TimeLength'):Wait()
09--/Will wait until this event fires, it will fire when TimeLength
10--\of this sound changes, i can't be sure that this is realiable
11--\so i would better do more checks or use the second method
12 
13wait(Sound.TimeLength)
14 
15sound:Stop()
16...

Sound.Ended

An event of Sound which fires when it ends, in your case you would use it instead of wait and yield until the event fires:

1...
2sound.SoundId = "rbxassetid://" .. input.Text
3sound:Play()
4 
5Module.ApplyText(btn, "Stop Sound")
6playing = true
7 
8sound.Ended:Wait()
9...

That way you can also get rid of Sound:Stop() and i personally prefer this method over the first one.

> Sources

GetPropertyChangedSignal

Sound.Ended

0
Thanks! It worked! For y'all internet surfers out there (I'm the original poster of this question), I'd recommend doing "Sound.Ended" because it's easier & doesn't require any checks. User#39895 0 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

just put the sound inside the gui and the play and stop in different buttons like:

1function Song()
2    local ID = script.Parent.Parent.id.Text
3    local sound = script.Parent.Parent.Parent.Music
4    Sound.SoundId = 'rbxassetid://'.. ID
5    Sound:Play()
6end
7script.Parent.MouseButton1Click:connect(Song)

and then

1function Stop()
2    script.Parent.Parent.Parent.Sound:Stop()
3end
4script.Parent.MouseButton1Click:connect(Stop)

-side note make sure the sounds in the gui and the buttons are in a frame id is a text box! :)

0
I put the sound inside of workspace so everyone inside a server would hear it (aka. global sounds) and that putting it inside of StarterGui makes it local which is not what I want & yes, the Id or... what I call, "input" is a text box, don't worry. User#39895 0 — 4y

Answer this question