I have made a region, that when you enter it, it plays a piece of music, and when the player leaves the music stops.
It seems to be playing OK
I have rigorously scrutinized the script, nothing seems wrong but it does not function properly.
It still plays when i leave the region?
It would be an honor if i could get some help.
local RegionPart = game.Workspace.Region
local Debounce = false
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local Region = Region3.new(pos1, pos2)
local Lantern = game.Workspace.Lantern
while true do
wait()
local PartsInRegion = workspace:FindPartsInRegion3(Region, Lantern, 1000)
for i, part in pairs(PartsInRegion) do
if part.Parent:FindFirstChild("Humanoid") ~= nil and not Debounce then
Debounce = true
print("Player is currently in the deep dark cave")
game.Workspace.CaveMusic:Play()
while true do
wait()
if workspace:IsRegion3Empty(Region, Lantern, 1000) then
print("It's empty")
game.Workspace.CaveMusic:Pause()
end
end
end
end
end
wait(1)
Debounce = false

1 comment
If you have different blocks separating the region from the non-region, you can just use a touched function to disable the music?