Hey Developers!
I’m trying to fix a script that isn’t working, but I’ve tried many “solutions” and it still doesn’t work!
The problem is when a player is outside of a certain area (aka the TriggerArea) it’s supposed to muffle the sound. When the player is in the TriggerArea, it disables the muffled audio effect, but it isn’t doing any of that and the audio is just muffled.
I’ve tried detecting the humanoid’s X, Y, and Z position every 0.1 seconds (since its an elevator and its moving, but it still isn’t working. (the reason for finding it is to detect if the player is still in the triggerarea)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local sound = game.Workspace.Elevator.Songs.Song1 -- feel free to change this to a song of your own to test it out!
local triggerArea = game.Workspace.Elevator.TriggerArea
local muffleEffect = sound:FindFirstChild("Muffle")
local function isPointInRegion(point, regionCenter, regionSize)
local halfSize = regionSize / 2
local min = regionCenter - halfSize
local max = regionCenter + halfSize
return point.X >= min.X and point.X <= max.X
and point.Y >= min.Y and point.Y <= max.Y
and point.Z >= min.Z and point.Z <= max.Z
end
while wait() do
humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
if humanoidRootPart then
if isPointInRegion(humanoidRootPart.Position, triggerArea.Position, triggerArea.Size) then
muffleEffect.Enabled = false
else
muffleEffect.Enabled = true
end
end
end
The muffle effect, trigger area, and sound are all in the right places, but everything I’ve tried just doesn’t seem to work. If you have any solutions or tips on how to fix this problem, please let me know!