Issue with creating sound regions using PartBoundsInBox

I am trying to create a temperate way for my sound regions as we only have one island right now. Basically I want it so that when you exit the region you hear the sailing/sea theme and when you spawn inside of it or go into it, it would play the respective islands theme. Though currently it does not work when your character spawns inside of the island and the sounds are flipped (enter ocean, plays highland isle theme, enter island plays sea theme) Here’s the code.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local music = game:GetService("SoundService")
local TS = game:GetService("TweenService")

local CFs = {
	cf_highland = CFrame.new(50,155,35)
}
local Sizes = {
	cs_highland = Vector3.new(134,113,134)
}

local returnWhiteList = {character:WaitForChild("HumanoidRootPart")}
local returningTable

local TI1 = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
local TI2 = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)

game:GetService("RunService").Heartbeat:Connect(function()
	local filteringType = Enum.RaycastFilterType.Whitelist
	local tempsize = Vector3.new(134,113,134)
	local tempcf = CFrame.new(50,155,35)
	
	local overlapParams = OverlapParams.new()
	overlapParams.FilterType = filteringType
	overlapParams.FilterDescendantsInstances = returnWhiteList
	
	returningTable = workspace:GetPartBoundsInBox(tempcf, tempsize, overlapParams)
	
	if returningTable[1] == returnWhiteList[1] then
		music.Highland_Isle:Play()
	else
		music.SailingTheme:Play()
	end
end)

Still been trying, no luck with it.

Fixed it. All I did was made it fade in out using a tween and kept them both playing on join but with 0 volume. No idea why that works, but it works.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.