How can I make these sounds play Globally for other clients?

I have this script that uses Animation Events to play a footstep sound everytime that it passes over it. It works completely fine, although it only works for the Client, and I would like it to be global instead so that all other players can hear them.

This is the code.

local RunAnimation = Instance.new('Animation')
RunAnimation.AnimationId = "rbxassetid://" -- Animation Id
RAnimation = Humanoid:LoadAnimation(RunAnimation)

RAnimation:GetMarkerReachedSignal("Step"):Connect(function()
	script.Sound:Play()
end)

This is how the script is set up with the sound
Screenshot 2023-01-29 015411

Its all in StarterCharacterScripts.

Thanks

You should fire a RemoteEvent from that client that is playing the animation.
The RemoteEvent will be listened by the server, and play the sound in serverSide, probably the sound should be inside a part of the character that fired the event in order the sound is 3d and coming from the character and not general in workspace.
In that way all players in server will be able to listen the sound.

-- LocalScript

-- Fetch service & event
local RS : ReplicatedStorage = game:GetService("ReplicatedStorage")
local event : RemoteEvent = RS:FindFirstChild("SoundEvent")

-- Play sound when event fired: server -> client
event.OnClientEvent:Connect(function(sound)
    sound:Play()
end)

-- Fire event client -> server
-- Pass sound as argument
RAnimation:GetMarkerReachedSignal("Step"):Connect(function()
    event:FireServer(script.Sound)
end)
-- ServerScript

local RS : ReplicatedStorage = game:GetService("ReplicatedStorage")
local event : RemoteEvent = RS:FindFirstChild("SoundEvent")

-- Fire event server -> clients when event fired client -> server
-- Pass sound as argument
event.OnServerEvent:Connect(function(plyr : Player, sound : Sound)
    event:FireAllClients(sound)
end)
2 Likes

Thats exactly what I said, but, if the sound is a child of the script, that sounds will not be 3d and not coming from the character that triggered the event, that will cause having a general sound on all clients, not even knowing where that sound is comming from

2 Likes

Alright, I did all of the steps that you said, but the sound still plays in 2D, how would I go about making the sound 3D (Playing the sound inside the character, that is)

1 Like

I don’t understand you don’t use the Server?

It will make what you’re doing 100x easier.

2D Are sounds that are not Parented to an Attachment, BasePart, (anything 3D basically)
Parent the Audio to an Instance and that should give you a 3D sound

1 Like

I am using a server script, I just need to know how to get the sound INTO the player, and then play it there

Script Im Using:

local event = game.ReplicatedStorage.FootstepEvent

local Sound = script.Sound

event.OnServerEvent:Connect(function(Plr)
	local Player = Plr
	local CHR = Player.Character
	print(Player.Name)
	Sound.Parent = CHR
	wait()
	Sound:Play()
end)
1 Like

This Simple:

local Character = script.Parent

local Audio = script.Sound:Clone()

Audio.Parent = Character:FindFirstChild("HumanoidRootPart")

Player.Character is a Model, not a BasePart or an Attachment, That’s why its still playing as a 2D sound

1 Like

Ah, I see. Thank you, the script now works.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.