I’m making a waterfall area in which when you get near the part that resembles the watersfall(below)
You hear a sound of rushing water.
So I watched a video by AlvinBlox: Roblox - Play music in different areas - Scripting tutorial (2020 updated version) - YouTube
And I made a folder called SoundRegions
Then made a folder in StarterGUI named SoundRegions.
In the folder I put my sound:
And I put a localscript that did everything.
Script
local SoundRegionsWorkspace = game.Workspace:WaitForChild(“SoundRegions”)
local Found = false
while wait(1) do
for i, v in pairs(SoundRegionsWorkspace: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
--Loop one by one through the parts table.
if part: FindFirstAncestor(game.Players.LocalPlayer.Name) then
print("Player was found")
Found = true
break
else
Found = false
print("Player was not found in region")
end
if Found == true then
--Play da music!
if script.Parent.SoundRegions[v.Name].IsPlaying == false then
script.Parent.SoundRegions[v.Name]:Play()
break
end
else
script.Parent.SoundRegions[v.Name]:Stop()
end
end
end
Idk why Devforum cut off a part of it
I’m pretty new to scripting so I tried to follow along with the video the best I could. I’m pretty sure what it does is that it constantly checks if the player is in a region, then if they are in the region, it checks if the audio is playing, and if it’s not playing, then it plays the audio until the player moves out of the region.
So the script didn’t work. I checked the names and made sure they were the same.
What I’m pretty sure is causing the script to not work is that I also have a script in which when you step into the water part, it plays an underwater sound. For that, I have a folder named “Water” in which there are parts which if you step into it, they play the underwater noise.
So here is a picture of the sound region with the waterfall part, which is named “waterfallwater”
Red= sound region
Blue=water part