You can write your topic however you want, but you need to answer these questions:
What do I want to achieve?
A sound region script that is consistent and isn’t affected by the most random of things.
What is the issue?
The issue is, this script is very buggy, and when The player pulls out a tool, the sound playing in the sound region that the player currently is in, stops: https://www.youtube.com/watch?v=rPWTV6-zvY0
What solutions have I tried so far?
-Changing the script
-Asking chatGPT (horrible mistake)
-Looking all over the dev forum for anyone who has ever experienced this before (of course not)
-Using ZonePlus
This is what a standard region looks like:
And this is the script:
local TweenService = game:GetService("TweenService")
local GoalOff = {Volume = 0}
local Inf = TweenInfo.new(0.5)
local activeTweens = {} -- Store active tweens for each SoundRegion
for _, v in pairs(game.Workspace:WaitForChild("SoundRegions"):GetChildren()) do
if v:IsA("BasePart") then
local SFX = v:FindFirstChildOfClass("Sound")
local OnValue = v:FindFirstChild("On")
v.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
if hit.Name == "HumanoidRootPart" then
if OnValue.Value == false then
OnValue.Value = true
local GoalOn = {Volume = SFX.VolumeV.Value}
local Anim = TweenService:Create(SFX, Inf, GoalOn)
SFX:Play()
task.wait()
Anim:Play()
end
end
end
end)
v.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
if hit.Name == "HumanoidRootPart" then
if OnValue.Value == true then
OnValue.Value = false
local Anim = TweenService:Create(SFX, Inf, GoalOff)
Anim:Play()
Anim.Completed:Wait()
SFX:Stop()
end
end
end
end)
end
end
Please help I’m being bombarded with messages in my “Thiskorrd” server to fix this issue and I do not know how.
Using .Touched for region detection is as broken and unreliable as it gets.
ZonePlus does work, since I have experimented with it before and it works like a charm for region detection. It’s made for region detection.
If you don’t want to try that method again, last reliable option is using a :GetPartBoundsInBox() function on a loop and use a table for who are in the region, removing them if they are not detected anymore.
Are you sure, I can share a sound region code, if you want too. Here’s an example (not tested may have errors):
local ZonePlus --Path to the module here
local container = --Your container
local newZone = ZonePlus.new(container)
local soundToPlay = Instance.new("Sound")
newZone.playerEntered:Connect(function(player)
if not player then return end
if game.Players:FindFirstChild(tostring(player)) == nil then return end
if soundToPlay.IsPlaying == false and not soundToPlay.IsPaused then
soundToPlay:Play()
else
soundToPlay:Resume()
end
end)
newZone.playerExited:Connect(function(player)
if not player then return end
if game.Players:FindFirstChild(tostring(player)) == nil then return end
if soundToPlay.IsPlaying == true then
soundToPlay:Stop()
end
end)
This is a local script in startercharacterscripts, hope this is going to help!
ZonePlus doesn’t seem to be working at all for me.
I got this script:
local TweenService = game:GetService("TweenService")
local Player = game.Players.LocalPlayer
local ZonePlus = require(game.ReplicatedStorage:WaitForChild("Zone"))
local Zones = game.Workspace:WaitForChild("SoundRegions")
local PlayingSound = game.SoundService.PlayingSound
for _, zone in pairs(Zones:GetChildren()) do
local trigger = ZonePlus.new(zone)
print(zone.Name.." Detected")
trigger.playerEntered:Connect(function(player)
print(player.Name.." Entered Zone: "..zone.Name)
if Player == player then
TweenService:Create(PlayingSound, TweenInfo.new(.5), {Volume = 0}):Play()
print("Starting Tween")
task.wait(.5)
PlayingSound.SoundId = zone:FindFirstChildOfClass("Sound").SoundId
print("Change Id")
local NextVolume = zone:FindFirstChildOfClass("Sound").Volume
print("Set Volume")
TweenService:Create(PlayingSound, TweenInfo.new(.5), {Volume = NextVolume}):Play()
print("End Sound tween")
end
end)
end
(sorry for the multiple print statements I was trying to debug)
from this video:
And that doesn’t seem on my game but works in his game.
Reading the comments of that video, I can tell I’m not the only one
I have a perfectly good script that works with :GetPartBoundsInBox() but with the amount of sound regions in my game (a lot), the game stutters every check. + I found that .Touched was a lot more responsive than a loop that checks every couple milliseconds.