Files
Hunter/scripts/OwnMovementAudio.client.luau
T
2026-11-30 00:19:33 +05:00

107 lines
3.7 KiB
Luau

--!strict
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local SoundService = game:GetService("SoundService")
local Sounds = require(ReplicatedStorage:WaitForChild("SniperEffects") :: ModuleScript)
local player = Players.LocalPlayer
local function cue(name: string, asset: string, looped: boolean): Sound
local sound = Instance.new("Sound")
sound.Name, sound.SoundId, sound.Looped = name, "rbxasset://sounds/" .. asset, looped
sound.Parent = SoundService
return sound
end
local steps = cue("HunterOwnSteps", "action_footsteps_plastic.mp3", true)
local jump = cue("HunterOwnJump", "action_jump.mp3", false)
local landing = cue("HunterOwnLanding", "action_jump_land.mp3", false)
local muted = Instance.new("SoundGroup")
muted.Name = "HunterOwnMovementSpatial"
muted.Volume = 0
muted.Parent = SoundService
local native = {Running = true, Jumping = true, Landing = true}
local groups: {[Sound]: SoundGroup?} = {}
local overridden: {Sound} = {}
local connections: {RBXScriptConnection} = {}
local humanoid: Humanoid? = nil
local root: BasePart? = nil
local function master(): number
return math.max(0, Sounds.setting("VolMaster", 1))
end
local function reset()
for _, connection in connections do connection:Disconnect() end
table.clear(connections)
for _, sound in overridden do
if sound.Parent and sound.SoundGroup == muted then sound.SoundGroup = groups[sound] end
end
table.clear(overridden)
table.clear(groups)
humanoid, root = nil, nil
steps:Stop()
jump:Stop()
landing:Stop()
end
local function watch(character: Model)
local human = character:WaitForChild("Humanoid", 10)
local part = character:WaitForChild("HumanoidRootPart", 10)
if player.Character ~= character or not human or not human:IsA("Humanoid") or not part or not part:IsA("BasePart") then return end
reset()
humanoid, root = human, part
local function muteDuplicate(child: Instance)
if child:IsA("Sound") and native[child.Name] and child.SoundGroup ~= muted then
groups[child] = child.SoundGroup
table.insert(overridden, child)
child.SoundGroup = muted
end
end
table.insert(connections, part.ChildAdded:Connect(muteDuplicate))
for _, child in part:GetChildren() do muteDuplicate(child) end
table.insert(connections, human.StateChanged:Connect(function(previous, current)
if part.Anchored or human.Health <= 0 then return end
local volume = master()
if volume <= 0 then return end
local sound = if current == Enum.HumanoidStateType.Jumping then jump
elseif current == Enum.HumanoidStateType.Landed and previous == Enum.HumanoidStateType.Freefall then landing else nil
if sound then
sound.Volume = volume * (if sound == jump then .26 else .21)
sound.TimePosition = 0
sound:Play()
end
end))
end
local added = player.CharacterAdded:Connect(watch)
local removing = player.CharacterRemoving:Connect(reset)
if player.Character then task.spawn(watch, player.Character) end
local update = RunService.Heartbeat:Connect(function()
local human, part = humanoid, root
local volume = master()
local speed = if part then Vector3.new(part.AssemblyLinearVelocity.X, 0, part.AssemblyLinearVelocity.Z).Magnitude else 0
local moving = human and part and not part.Anchored and human.Health > 0 and human.MoveDirection.Magnitude > .05
and human.FloorMaterial ~= Enum.Material.Air and speed > 1.5 and volume > 0
if moving then
steps.Volume = .25 * volume
steps.PlaybackSpeed = math.clamp(speed / 24, .75, 1.5)
if not steps.Playing then steps:Play() end
elseif steps.Playing then
steps:Stop()
end
end)
script.Destroying:Once(function()
added:Disconnect()
removing:Disconnect()
update:Disconnect()
reset()
steps:Destroy()
jump:Destroy()
landing:Destroy()
muted:Destroy()
end)