My music script switches from one set of music to another when you're within a certain radius of a player, but if the player leaves while in your radius the music is stuck on danger/combat and doesn't revert back to the safe/peaceful music. Is there a way to detect when a player in your radius leaves to revert the music back to normal?
repeat wait() until game.Players.LocalPlayer.Character:FindFirstChild("StatInfo") ~= nil
local MusicSystem = script.Parent.Play
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Char = game.Players.LocalPlayer.Character
local Combat = false
local Reset = false
-------------------------------------------------------------------------------
--Combat/Idle Mode--
-------------------------------------------------------------------------------
game:GetService('RunService').RenderStepped:Connect(function()
for i, v in pairs(game.Players:GetChildren()) do
if v.Name ~= Char.Name and Combat == false and (Char.HumanoidRootPart.Position - v.Character:FindFirstChild("HumanoidRootPart").Position).magnitude <= (150) and v.Character.StatInfo.IsCrouching.Value == false then
Combat = true
MusicSystem.Audio:Remove()
local Combat = MusicSystem.Mode.Combat.Audio:Clone()
Combat.Parent = MusicSystem
MusicSystem.Disabled = true
MusicSystem.Disabled = false
elseif v.Name ~= Char.Name and Combat == true and (Char.HumanoidRootPart.Position - v.Character:FindFirstChild("HumanoidRootPart").Position).magnitude >= (150) then
Combat = false
MusicSystem.Audio:Remove()
local Idle = MusicSystem.Mode.Idle.Audio:Clone()
Idle.Parent = MusicSystem
MusicSystem.SelectedSong.PlaybackSpeed = 1
MusicSystem.Disabled = true
MusicSystem.Disabled = false
end
end
end)
