I have an AI that reacts when you make a loud noise, but i've encountered a problem. Let's say i shoot a gun. If I shoot the gun the AI should hear it, but if i only shoot the gun once, the playback loudness = 0. If i shoot the gun twice it still says 0, UNLESS i shoot the gun twice back to back quickly (double click). Any solutions? This happens for all the sounds except the walking ones, which work normally.
local Monster = script.Parent
local HumanoidRootPart = Monster:FindFirstChild("HumanoidRootPart")
local Humanoid = Monster:FindFirstChild("Humanoid")
local AnimationsFolder = Monster:FindFirstChild("Settings")
local Settings = Monster:FindFirstChild("Settings")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
--Extra Values
local Magnitude
local Percent
local Amplitude
local MaxVolume = 30
local MinimumVolume = 0.5
--Bool Values
local Chasing = false
local HasTarget = false
--Functions
--Events
ReplicatedStorage.MakeSound.OnServerEvent:Connect(function(Player, SoundVolume, PlaybackLoudness)
if Chasing == false then
local PositionOfSound = Player.Character:FindFirstChild("HumanoidRootPart").Position
Magnitude = (HumanoidRootPart.Position - Player.Character:FindFirstChild("HumanoidRootPart").Position).Magnitude
Amplitude = math.clamp(PlaybackLoudness / MaxVolume, 0, 1)
print(PlaybackLoudness)
local MaxDistance = Amplitude * SoundVolume
if Magnitude / 2 <= PlaybackLoudness then
Humanoid:MoveTo(PositionOfSound)
end
end
end)
