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

Sound Glitches On Death?

Asked by
yoshi8080 445 Moderation Voter
9 years ago

Making a little sound stage thing for a friend, however it's a bit glitchy after a player dies. No errors though. This is a local script placed in StarterGui

Problem: After player once or more, the sound stops and won't play.

01Sounds = script:WaitForChild'SongFolder'
02 
03Player = game.Players.LocalPlayer
04PlayerGui = Player.PlayerGui
05Leaderstats = Player:WaitForChild'leaderstats'
06Stage = Leaderstats:WaitForChild'Stage'
07 
08Song1 = Sounds:WaitForChild'Sound1'
09Song2 = Sounds:WaitForChild'Sound2'
10Song3 = Sounds:WaitForChild'Sound3'
11Song4 = Sounds:WaitForChild'Sound4'
12 
13 
14if Stage.Value == 1 and Song1.IsPlaying ~= true then
15Song1:Play()
View all 41 lines...

2 answers

Log in to vote
1
Answered by
XAXA 1569 Moderation Voter
9 years ago

Problem

Every time the player spawns, if Stage.Value is > 1, the appropriate song will not play.

Suggestions

Given how you name your sounds, it would be best if these were stored in a table so you can iterate through it and index them neatly. As a plus, you can get rid of those ugly redundant if-statements.

Solution

01Sounds = script:WaitForChild'SongFolder'
02 
03local Songs = {
04Sounds:WaitForChild'Sound1',
05Sounds:WaitForChild'Sound2',
06Sounds:WaitForChild'Sound3',
07Sounds:WaitForChild'Sound4'
08}
09 
10Player = game.Players.LocalPlayer
11PlayerGui = Player.PlayerGui
12Leaderstats = Player:WaitForChild'leaderstats'
13Stage = Leaderstats:WaitForChild'Stage'
14 
15function PlaySound(id) -- Stops all the songs that are currently playing, then plays the sound.
View all 25 lines...
Ad
Log in to vote
0
Answered by 9 years ago
01Sounds = script:WaitForChild'SongFolder'
02 
03Player = game.Players.LocalPlayer
04PlayerGui = Player.PlayerGui
05Leaderstats = Player:WaitForChild'leaderstats'
06Stage = Leaderstats:WaitForChild'Stage'
07 
08Song1 = Sounds:WaitForChild'Sound1'
09Song2 = Sounds:WaitForChild'Sound2'
10Song3 = Sounds:WaitForChild'Sound3'
11Song4 = Sounds:WaitForChild'Sound4'
12 
13if Stage.Value == 1 and Song1.IsPlaying ~= true then
14Song1:Play()
15end
View all 40 lines...

Tell me if it works, didn't test it in studio.

0
I think line 37 is wrong, it's seems incomplete yoshi8080 445 — 9y
0
oops, for i,v = 1,4 do See if that works? I'm not good with i,v. Dominus113 0 — 9y
0
I see yoshi8080 445 — 9y

Answer this question