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!