Hello, I’m still new here and I’ve been trying to fix this for the past 45 minutes or more I am trying to make a soundregion where whenever you enter the region space it plays an audio which is the audio variable. However, I am getting a problem everytime it just keeps looping it all the time and it doesn’t even play the song past 5 seconds it just restarts…
Here is my code:
local SoundService = game:GetService("SoundService")
local RegionPart = game.Workspace.RegionPart
local Audio = game.SoundService.Sound
local Found = false
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local region = Region3.new(pos1,pos2)
RegionPart:Destroy()
while true do
wait(1)
local partsInRegion = workspace:FindPartsInRegion3(region, nil, 100)
for i, region in pairs(partsInRegion) do
if region.Parent:FindFirstChild("Humanoid") ~= nil then -- checks if humanoid is in region
print("Found Player:"..region.Parent.Name)
Found = true
if Found == true then
Audio:Play()
print("Audio is playing.")
break
end
end
end
end
Also, the script is running in the output as intended but it keeps running to many times! I just want it to keep printing my name but only plays the audio once. (Also yes I know I could just do Audio.Playing = true but then it’ll play globally I just want it to play client sided so that only the players in the region can hear it not anyone outside of the region.