How do I make my script stop the correct sound?
I created a script where when you click, it opens a menu with the songs you can play, and when you click a song it plays it and an animation, and when you click stop it should stop the song and animation. When I run a test server with two players, I have them both play a song. Sometimes when I click stop on one player it will stop the other players song or not stop the song at all. Does anyone know why this is happening?
SERVER SCRIPT:
01 | unequipt = game.ReplicatedStorage.Unequpit |
02 | stopsong = game.ReplicatedStorage.StopSong |
03 | choosesong = game.ReplicatedStorage.ChooseSong |
04 | songstopped = game.ReplicatedStorage.songstopped |
06 | game.Players.PlayerAdded:Connect( function (player) |
07 | player.CharacterAdded:Connect( function (character) |
08 | if player.TeamColor = = BrickColor.new( "Really red" ) then |
09 | f = game.ReplicatedStorage [ "British Fife" ] |
10 | f:Clone().Parent = player.Backpack |
11 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 1. Text = "The British Grenadiers" |
12 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 2. Text = "The Girl I Left Behind Me" |
13 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 3. Text = "Lilliburlero" |
14 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 4. Text = "Rule Britannia" |
16 | if player.TeamColor = = BrickColor.new( "Really blue" ) then |
17 | f = game.ReplicatedStorage [ "French Fife" ] |
18 | f:Clone().Parent = player.Backpack |
19 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 1. Text = "La Grenadier" |
20 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 2. Text = "La Charge" |
21 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 3. Text = "La Diane" |
22 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 4. Text = "La Pa Cadence" |
28 | choosesong.OnServerEvent:Connect( function (player,animid,songnumber) |
29 | song = Instance.new( "Sound" ) |
30 | if player.TeamColor = = BrickColor.new( "Really red" ) then |
31 | song.Parent = player.Character:FindFirstChild( "British Fife" ).Handle |
33 | if player.TeamColor = = BrickColor.new( "Really blue" ) then |
34 | song.Parent = player.Character:FindFirstChild( "French Fife" ).Handle |
37 | animation = Instance.new( "Animation" ) |
39 | trackanimation = game.Workspace [ player.Name ] .Humanoid:LoadAnimation(animation) |
42 | player.Character.Humanoid.WalkSpeed = 8 |
43 | song.Ended:Connect( function () |
44 | songstopped:FireClient(player) |
46 | player.Character.Humanoid.WalkSpeed = 16 |
54 | stopsong.OnServerEvent:Connect( function (player) |
58 | player.Character.Humanoid.WalkSpeed = 16 |
64 | unequipt.OnServerEvent:Connect( function (player) |
68 | player.Character.Humanoid.WalkSpeed = 16 |
LOCAL SCRIPT:
01 | unequipt = game.ReplicatedStorage.Unequpit |
02 | stopsong = game.ReplicatedStorage.StopSong |
03 | choosesong = game.ReplicatedStorage.ChooseSong |
04 | songstopped = game.ReplicatedStorage.songstopped |
06 | player = game.Players.LocalPlayer |
09 | script.Parent.Equipped:Connect( function (mouse) |
10 | mouse.Button 1 Down:Connect( function () |
11 | if player.Character:FindFirstChild( "British Fife" ) then |
12 | if not player.PlayerGui:WaitForChild( "ScreenGui" ).Stop.Visible and not player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.Visible then |
13 | player.PlayerGui.ScreenGui.Frame.Visible = true |
21 | script.Parent.Unequipped:Connect( function () |
23 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.Visible = false |
24 | player.PlayerGui:WaitForChild( "ScreenGui" ).Stop.Visible = false |
29 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 1. MouseButton 1 Click:Connect( function () |
30 | choosesong:FireServer( 4054455538 , 4009405494 ) |
31 | player.PlayerGui.ScreenGui.Frame.Visible = false |
32 | player.PlayerGui.ScreenGui.Stop.Visible = true |
34 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 2. MouseButton 1 Click:Connect( function () |
35 | choosesong:FireServer( 04116459147 , 4115819618 ) |
36 | player.PlayerGui.ScreenGui.Frame.Visible = false |
37 | player.PlayerGui.ScreenGui.Stop.Visible = true |
39 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 3. MouseButton 1 Click:Connect( function () |
40 | choosesong:FireServer( 04116482197 , 4115832422 ) |
41 | player.PlayerGui.ScreenGui.Frame.Visible = false |
42 | player.PlayerGui.ScreenGui.Stop.Visible = true |
44 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.TextButton 4. MouseButton 1 Click:Connect( function () |
45 | choosesong:FireServer( 04116506453 , 4115835480 ) |
46 | player.PlayerGui.ScreenGui.Frame.Visible = false |
47 | player.PlayerGui.ScreenGui.Stop.Visible = true |
51 | script.Parent.Unequipped:Connect( function () |
56 | player.PlayerGui:WaitForChild( "ScreenGui" ).Stop.TextButton.MouseButton 1 Click:Connect( function () |
58 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.Visible = true |
59 | player.PlayerGui:WaitForChild( "ScreenGui" ).Stop.Visible = false |
64 | songstopped.OnClientEvent:Connect( function () |
65 | player.PlayerGui:WaitForChild( "ScreenGui" ).Stop.Visible = false |
66 | player.PlayerGui:WaitForChild( "ScreenGui" ).Frame.Visible = true |