How would I play sound through a characters head through a server script?

I’m trying to create a script that allows you to press a key on your keyboard which then plays a sound through your characters head. (Like video game character voicelines) I’m basically trying to figure out how to find the audio through the character, and play it through a server script after a remote event fires from a local script.

I’ve been able to do it on a local script, but I have no idea how to transfer it over to a server script.
I’ve tried remote events but I’m not sure If I used them correctly.
This script also has an infinite yield issue that I’m still stuck on. (I tried using “, math.huge” to no success)

Heres the code I used;

–Client (located in StarterCharacterScripts)
local Event = game.ReplicatedStorage.RemoteEvents:WaitForChild(“KeybindEvent”)
local UIS = game:GetService(“UserInputService”)

task.wait(.5)

local Player = game.Players.LocalPlayer

local sound = Instance.new(“Sound”)
sound.SoundId = “rbxassetid://6972501837”
sound.Parent = script.Parent:WaitForChild(“Head”)
sound.Volume = .5
sound.Name = “Medic”

UIS.InputBegan:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.E then
Event:FireServer()
sound:Play() – plays the sound effect locally, mostly for debugging
end
end)

–Server (located in ServerScriptService)
local Event = game.ReplicatedStorage.RemoteEvents:WaitForChild(“KeybindEvent”)

Event.OnServerEvent:Connect(function(player)
print(“working”)
local head = player.Character:FindFirstChild(“Head”)
local sound = head:WaitForChild(“Medic”) – “Medic” is the sound im trying to play
sound:Play()
sound.Volume = 5

end)

Help would be much appreciated!

1 Like

You are making the sound on the client side which wont replicate to the server.

OOooh alright, that makes a lot more sense, thank you!

(Ima test this out rq to see if I can figure it out, then I’ll mark this post as solved.)

1 Like

Alright, that solved it.
I had a morphing script for the characters that was serversided and I applied the creation of the sound instance to that which fixed the script, thanks a bunch! I was really stumped on this.

1 Like

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