I have a custom emote in my game and I also have audio for the emote, I need help writing a script that will play audio coming from the character as long as the animation is running, and stop when the animation stops, I want all players to hear this music, how can I do it? Heres the script im using
local keyPressed = Enum.KeyCode.P --Another example Enum.KeyCode.N
local animationId = “8999377853” --Change to your animation Id
local userInputService = game:GetService(“UserInputService”)
local player = game:GetService(“Players”).LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)
local animation = Instance.new(“Animation”)
animation.AnimationId = “rbxassetid://”…animationId
local animationTrack = humanoid:LoadAnimation(animation)
userInputService.InputBegan:Connect(function(input,isTyping)
if isTyping then return end
if input.KeyCode == keyPressed then
if not animationTrack.IsPlaying then
animationTrack:Play()
else
animationTrack:Stop()
end
end
end)