In my game, there are three areas, and I'd like to make it so when you're in one area, certain music plays, and when you're in another area, different music plays. How do I do this?
local areas = { [1]= { Name = "Town", Center = Vector3.new(0,0,0), Music = "13333337" }, [2] = { Name = "Toilet", Center = Vector3.new(50,0,0), Music = "13333337" }, [3] = { Name = "Wilderness", Center = Vector3.new(0,0,50), Music = "13333337" } } local me = game.Players.LocalPlayer local sound = Instance.new("Sound") local currentArea = nil local function getClosestArea() local closestArea = 1 local minimumDistance = me:DistanceFromCharacter(area[1]) for i,area in pairs (areas) do local distance = me:DistanceFromCharacter(area.Center) if distance < minimumDistance then minimumDistance = distance closestArea = i end end return closestArea end while wait(1) do local closestArea = getClosestsArea() areaData = areas[closestArea] if currentArea ~= areaData.Name then currentArea = areaData.Name sound:Stop() sound.SoundId = "rbxassetid://"..areaData.Music sound:Play() end end