In my previous post, I was trying to fix the issue with the sound not playing when entering the zone which I fixed on my own. Now with more islands in the game, I need this to go through all of the CFrames and their sizes to see where the player is currently is to play the islands respective music.
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local music = game:GetService("SoundService")
local TS = game:GetService("TweenService")
local rems = game:GetService("ReplicatedStorage").Rems
local CFs = {
cf_highland = CFrame.new(50,155,35),
cf_lowtide = CFrame.new(-693,45,487)
}
local Sizes = {
cs_highland = Vector3.new(134,113,134),
cs_lowtide = Vector3.new(222,290,261)
}
local returnWhiteList = {character:WaitForChild("HumanoidRootPart")}
-- when a new character loads, set it to be the white list
-- this allows the music to be heard after the first character dies
player.CharacterAdded:Connect(function(char)
returnWhiteList = {char:WaitForChild("HumanoidRootPart")}
end)
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)
rems.LoadPlr.OnClientEvent:Connect(function()
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
TS:Create(music.Highland_Isle, TI2, {Volume = 0}):Play()
TS:Create(music.SailingTheme, TI1, {Volume = 0.5}):Play()
else
TS:Create(music.Highland_Isle, TI1, {Volume = 0.5}):Play()
TS:Create(music.SailingTheme, TI2, {Volume = 0}):Play()
end
end)
end)
The arrays I want to loop through are,
local CFs = {
cf_highland = CFrame.new(50,155,35),
cf_lowtide = CFrame.new(-693,45,487)
}
local Sizes = {
cs_highland = Vector3.new(134,113,134),
cs_lowtide = Vector3.new(222,290,261)
}
I’m just super confused on how I would implement this using PartBoundsInBox.