So I am making an obby where, if i touch a checkpoint that is not the color of my team, it changes my team color to the color of the checkpoint (automatically done by the "AllowTeamColorChangeOnTouch" attribute), it then stops all audios named "Audio" (the names for all the main music for each stage) playing, and plays an audio with the name "Audio" in the same file as the checkpoint.
The bottom part of the script is a hard-coded check to change the music specifically for the first stage, because there are multiple checkpoints in the stage which breaks the audio since the script stops and starts the audio each time you touch a checkpoint, so it would almost stop the audio if you were walking around enough, and i couldnt get around it so that was the simplest option.
for _, v in ipairs(workspace:GetDescendants()) do if v.ClassName == "SpawnLocation" then v.Touched:Connect(function() if game.Players.LocalPlayer.TeamColor == not v.TeamColor then for _, e in ipairs(workspace:GetDescendants()) do if e.ClassName == "Sound" and e.Name == "Audio" then e.Playing = false end end v.Parent:FindFirstChild("Audio").Playing = true end end) end end workspace.Stages.Lobby.MusicPlayer.Touched:Connect(function() workspace.Stages.Lobby.Audio.Playing = true end)
I double checked every step of the script and im not sure what is wrong, I also thought a potential problem was that the TeamColor of the player updated before the .Touched check, which would make the script think that the player is just touching the same checkpoint, however when I disabled the AllowTeamColorChangeOnTouch attribute on the checkpoint the problem still persisted, and it doesn't even stop the other audios so im not sure what is wrong here.
Also just so you know, I double checked and made sure all the team colors and audio names were correct, so that cannot be the problem.
There's no such thing as "== not", use "~=" instead.
I haven't fully read your post yet, but this is something I came across.
for _, v in ipairs(workspace:GetDescendants()) do if v.ClassName == "SpawnLocation" then v.Touched:Connect(function() if game.Players.LocalPlayer.TeamColor ~= v.TeamColor then for _, e in ipairs(workspace:GetDescendants()) do if e.ClassName == "Sound" and e.Name == "Audio" then e.Playing = false end end v.Parent:FindFirstChild("Audio").Playing = true end end) end end workspace.Stages.Lobby.MusicPlayer.Touched:Connect(function() workspace.Stages.Lobby.Audio.Playing = true end)