I have a script that is supposed to play music in areas (the area are parts that are transparent and you can walk thought them), but when you reset or die the music does not play anymore in the area.Can someone plz help me.
code:
local plr = game.Players.LocalPlayer
local soundRegions = workspace:WaitForChild("SoundRegions")
soundRegions = soundRegions:GetChildren()
local soundManagement = {}
for _,region in pairs(soundRegions) do
local info = {}
local region3 = Region3.new(region.Position-(region.Size/2),region.Position+(region.Size/2))
region.Transparency = 1
info.Region = region3
info.Sound = script.SoundRegions:FindFirstChild(region.name).Sound
table.insert(soundManagement,info)
end
game:GetService("RunService").RenderStepped:Connect(function()
for _,soundInfo in pairs(soundManagement) do
local region = soundInfo.Region
local sound = soundInfo.Sound
local parts = workspace:FindPartsInRegion3WithWhiteList(region,plr.Character:GetDescendants())
if #parts > 0 then
if not sound.IsPlaying then
sound:Play()
end
else
sound:Stop()
end
end
end)
What I tried to do to fix it.
local plr = game.Players.LocalPlayer
local soundRegions = workspace:WaitForChild("SoundRegions")
soundRegions = soundRegions:GetChildren()
local soundManagement = {}
for _,region in pairs(soundRegions) do
local info = {}
local region3 = Region3.new(region.Position-(region.Size/2),region.Position+(region.Size/2))
region.Transparency = 1
info.Region = region3
info.Sound = script.SoundRegions:FindFirstChild(region.name).Sound
table.insert(soundManagement,info)
end
game:GetService("RunService").RenderStepped:Connect(function()
for _,soundInfo in pairs(soundManagement) do
local region = soundInfo.Region
local sound = soundInfo.Sound
local parts = workspace:FindPartsInRegion3WithWhiteList(region,plr.Character:GetDescendants())
if #parts > 0 then
if not sound.IsPlaying then
sound:Play()
end
plr.Character.Humanoid.Died:Connect(function()
sound:Stop()
end)
sound:Stop()
end
end
end)

2 comments
Where is the script located?
in starter gui