I'm trying to find any sounds that are behind a wall, but the script says it is always behind a wall. Here's my code:
--Services
local RS = game:GetService("RunService")
--Instances
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
--Tables
local sources = {}
local ignore = {}
wait(1)
for i,v in pairs(workspace:GetChildren()) do
for i,b in pairs(v:GetDescendants()) do
if b:IsA("Humanoid") then
table.insert(ignore,v) --Add all players/dummies to the ignore list
end
end
end
for i,v in pairs(workspace:GetDescendants()) do --Get the source of every sound in the game.
if v:IsA("Sound") and v.Parent:IsA("BasePart") then
for i,chars in pairs(char:GetDescendants()) do
if v.Parent ~= chars then
table.insert(sources,v.Parent) --Insert the source into a table
end
end
end
end
while RS.RenderStepped:Wait(0.01) do
wait()
for i,source in pairs(sources) do
wait()
local ray = Ray.new(char:WaitForChild("Head").Position,source.Position) --Cast a ray to the source
table.insert(ignore,char)
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,ignore)
if hit and hit.Name ~= source.Name then --Find if the player is behind a wall or not
print("Behind a wall")
else
if hit and hit.Name == source.Name then
print("Not behind a wall")
end
end
end
end
