What do you want to achieve? I want to achieve a system where when the player walks or jumps, or does anything that produces an action, it activates a sound audible on both the client and server side. For example, I am walking on a sandy object: it produces a sound of sand which can be heard by other clients too, but obviously, within the range.
What is the issue? I don’t know if I should make the script server-side, or if I should make it local, but firing a remote event to the server, playing the sound inside the player humanoidRootPart, but I still don’t know.
I’ve got the script. If it is needed for you to check it, tell me. Thanks in advance!
Why do you need it on the server? You should use remoteevents and fireallclients with the parent of the sound and the id of the sound (along with other properties) and play it only on the clients
You could make it fully client sided by handling other players sounds on your client if they’re within a certain radius from you. Although i don’t know if you can detect animation events on other players walking animations from your own client if youre using animation events to play footstep sounds. So dont expect this to work
True but i personally think that footstep sounds and such shouldnt be handled and detected from the server, animations are handled on the client and using fireallclients would delay the sound
Also, theres a property under SoundService called ” RespectFilteringEnabled”. You could just enable/disable that and have all of the sounds needed for each footstep material and action inside your character and play them in a local script, everyone will hear it.
Although this will work for every sound being played from the client, not only in your character so it might get annoying
What do you mean it doesn’t need a server? Are the footsteps sounds playing for everyone, even if called locally? I don’t think you’re understanding. I want the custom footsteps I created to be heard by other players, so it is more realistic.
What do you mean? Can you all be more specific? I can show you all the script.
local RpS = game:GetService("ReplicatedStorage")
local RS = game:GetService("RunService")
local plrs = game:GetService("Players")
local footsteps = RpS.Footsteps
local plr = plrs.LocalPlayer
local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local HRP = char:WaitForChild("HumanoidRootPart")
local timePosition = 0
local baseStepLength = 10
local distanceFromGround = hum.HipHeight + HRP.Size.Y / 2
local air = Enum.Material.Air
local playing
local getGroundResults = function() : RaycastResult
local origin = HRP.Position
local direction = -HRP.CFrame.UpVector * (distanceFromGround + 5)
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Exclude
params.FilterDescendantsInstances = {char}
return workspace:Raycast(origin, direction, params)
end
local getGroundMaterialVariant = function() : string?
local groundResults = getGroundResults()
if groundResults then
local instance = groundResults.Instance
if not instance:IsA("BasePart") and instance.Transparency < .05 then return end
return instance.MaterialVariant
end
return
end
local getCurrentSong = function() : Sound
local materialVariant = getGroundMaterialVariant()
local material = hum.FloorMaterial
local song = HRP.Air :: Sound
if material ~= air and materialVariant then
local songGroup = HRP[material.Name] :: SoundGroup
song = songGroup:FindFirstChild(materialVariant) :: Sound?
end
return song
end
local stopSong = function()
if playing then
playing:Stop()
playing = nil
end
end
for _, song in HRP:GetChildren() do
if song:IsA("Sound") then
song:Destroy()
end
end
for _, song in footsteps:GetChildren() do
song:Clone().Parent = HRP
end
RS.Heartbeat:Connect(function(DT)
local speed = char:GetAttribute("AverageSpeed") or 0
local moveDirection = hum.MoveDirection
local isMoving = moveDirection.Magnitude > 0
local nextSong = getCurrentSong()
if not nextSong then
stopSong(playing)
return
end
if isMoving or nextSong.Name == "Air" then
local nextLength = nextSong.TimeLength
local nextTimePos = timePosition % nextLength
if playing ~= nextSong then
stopSong()
playing = nextSong
playing:Play()
if nextSong.Name ~= "Air" then
playing.TimePosition = nextTimePos
end
end
timePosition = playing.TimePosition
if nextSong.Name ~= "Air" then
playing.PlaybackSpeed = speed/baseStepLength
end
else
stopSong(playing)
end
end)
It’s currently on local script as I’ve changed it momentarily.
No?
I see pattern of wrong thinking here so instead:
Make script run locally that plays sound for each humanoid’s footsteps
Server part is at best FloorMaterial replication.
Killing caughcaugh “stable” ping is bad.
– go through player characters
– bind events to them
– FLOOR METERIAL CHANGED (attribute/remote event doesnt metter how you will check it)!? → CHANGE SOUND ID