I have a sound region system that I edited and modified off of a tutorial on Youtube. I have a region folder in workspace that contains multiple region parts. If the local player enters the region, a sound should be cloned to the parent of them and play. Although I am running into a few problems. Once the local player enters the region, the sound is cloned and plays. Although if another player then enters the same region, the sound from the other player stops and cloned into the new player in the region. Basically, the sound only plays for one player in a region even though there are multiple people in the region.
I appreciate some assistance, I have a local script in StarterPlayerScripts. I think it has to do something with the RunService Rendered function part. Which is why I am only going to provide a bit of the script considering that the script has a lot of functions that do not interfere with the problem that I am currently having.
RunService Section:
-- Start of local script
repeat
task.wait()
until game:GetService("Players").LocalPlayer.Character ~= nil and game:IsLoaded() == true and game:GetService("Players").LocalPlayer.CharacterAdded
local player = game.Players.LocalPlayer
local function getboundingBox()
local boxPosition = player.Character.PrimaryPart.CFrame
local boxSize = Vector3.new(1, 1, 1)
local Overlap = OverlapParams.new()
Overlap.FilterType = Enum.RaycastFilterType.Blacklist;
Overlap.FilterDescendantsInstances = {player.Character}
local params = Overlap
local objectsInSpace = workspace:GetPartBoundsInBox(boxPosition, boxSize, params)
local songsregion = {}
for i, v in pairs(objectsInSpace) do
if v:FindFirstChildOfClass("Sound") and v:IsDescendantOf(script.MusicRegion.Value) then
table.insert(songsregion, v)
end
end
return songsregion
end
local currentsongplaying
local songcloneplay
local TweenService = game:GetService("TweenService")
local TweenInfoW = TweenInfo.new(1)
local volumelastsoundtoreach = 0.5
local currenttweensound
-- RenderStepped Section
game:GetService("RunService").RenderStepped:Connect(function(ds)
if player.Character and player.Character.PrimaryPart then -- Checking if player exists before continuing
if player:FindFirstChild("MuteMusicc") and player.MuteMusicc.Value == false then -- Mute thing
if currentsongplaying and songcloneplay and songcloneplay.Volume == 0 and songcloneplay:FindFirstChild("UnmuteSong") then
songcloneplay.UnmuteSong:Destroy()
local sound = songcloneplay
if sound:FindFirstChild("OldVolume") then
sound.Volume = sound.OldVolume.Value
end
end
end
local regionmusic = getboundingBox()
if not (#regionmusic == 0) then
if not currentsongplaying then
local soundslist = {}
for _, v in pairs(regionmusic[1]:GetChildren()) do
if v:IsA("Sound") then
table.insert(soundslist, v)
end
end
if #soundslist >= 1 then
local soundselected = soundslist[1]
if selectedSound ~= soundselected then
selectedSound = soundselected
if player:FindFirstChild(selectedSound.Name) then
songcloneplay = player:FindFirstChild(selectedSound.Name)
tweenVolume(songcloneplay.Volume)
else
if songcloneplay then
songcloneplay:Stop()
end
songcloneplay = soundselected:Clone()
songcloneplay.Parent = player
songcloneplay:Play()
tweenVolume(songcloneplay.Volume)
for _, soundChild in pairs(player:GetChildren()) do
if soundChild:IsA("Sound") and soundChild ~= songcloneplay then
soundChild:Stop()
soundChild:Destroy()
end
end
end
end
end
end
end
One last thing, each player seems to be getting this error whenever they enter the region:
Players.Player1.PlayerScripts.SoundsRegionLocal:207: attempt to index nil with ‘Parent’
Line 207: songcloneplay.Parent = player
Thanks.