Im making Region3 for sounds. I followed Alvin Blox’s tutorial but im now on my own. I wanted to change how the music is played but its not working. Anything helps thanks!
Code [No Sound Is Played The Only Thing That Changes Is The Sounds Time Position]:
local soundRegions = game.Workspace.Regions
local found = false
while wait() do
for i, v in pairs(soundRegions:GetChildren()) do
found = false
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
for _, part in pairs(parts) do
if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
found = true
break
else
found = false
end
end
if found then
--// Play Music
if script.Sound.IsPlaying == false then
script.Sound.SoundId = "rbxassetid://"..v.SoundId.Value
script.Sound:Play()
break
end
else
script.Sound:Stop()
end
end
end
local soundRegions = workspace.Regions
local sound = script.Sound
while wait() do
for i, v in pairs(soundRegions:GetChildren()) do
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character,math.huge)
local found = #parts > 0 and true or false
if found then
--// Play Music
if sound.IsPlaying == false then
sound.SoundId = "rbxassetid://"..v.SoundId.Value
sound:Play()
break
end
else
sound:Stop()
end
end
end
You already have it set up so it works with a Whitelist, so just check if the returned table is greater than 0 or not to determine if the player was found in the region
And I think ForeverHDs ZonePlus should be a better way to handle what you need as it works with Region3s, not sure if it works in localscripts as I have never used it
Sorry about that, I accidentally mixed up the order. While fixing this up I noticed that it could be catching an error with the table. By getting all the things in the table you are also getting this like scripts, attachments, etc.
Try this. Not sure if this could be an issue, but it’s worth giving a try.
local WhitelistTable = {}
local CharacterPartsTable = game.Players.LocalPlayer.Character:GetDescendants()
for i = 1,#CharacterPartsTable do
if CharacterPartsTable[i]:IsA("BasePart") then
table.insert(WhitelistTable, CharacterPartsTable[i])
end
end
local parts = game.Workspace:FindPartsInRegion3WithWhiteList(
region,
WhitelistTable,
math.huge,
)
Oh right, forgot it needs to be in a table, do this
local soundRegions = workspace.Regions
local sound = script.Sound
while wait() do
for i, v in pairs(soundRegions:GetChildren()) do
local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
local parts = workspace:FindPartsInRegion3WithWhiteList(region, {game.Players.LocalPlayer.Character}, math.huge)
local found = #parts > 0 and true or false
print(parts,found)
if found then
--// Play Music
if sound.IsPlaying == false then
sound.SoundId = "rbxassetid://"..v.SoundId.Value
sound:Play()
break
end
else
sound:Stop()
end
end
end
So it looks like the audio is playing but theres nothing stopping it from playing. So when your in the region it prints PLAYING tons of times. There for the audio not playing.