Need help with playing sound from LocalScript

Hello, the lost people,

I need help with playing audio from local script. I try to make my own piggy roleplay with the jumpscare button. I tested the game with my Lil bro, but the sound did not play after my Lil bro press the button.

Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer

local gui = script.Parent
local button = gui.Jumpscare

local function playJumpscare(target)
	target.Head.Jumpscare:Play()
	target.Head.Theme.Playing = false
	wait(1)
	target.Head.Hit:Play()
end

local playing = false
button.MouseButton1Click:Connect(function()
	if player.Character then
		local character = player.Character
		if character:WaitForChild("Humanoid").Health > 0 then
			local humanoid = character:WaitForChild("Humanoid")
			if humanoid:FindFirstChild("Attack") and not playing then
				local animation = humanoid:LoadAnimation(humanoid:FindFirstChild("Attack"))
				playing = true
				animation:Play()
				humanoid.WalkSpeed = 0
				playJumpscare(character)
				animation.Stopped:Wait()
				character.Head.Theme.Playing = true
				playing = false
				humanoid.WalkSpeed = 16
			end
		end
	end
end)

Did any errors pop up in the output?

There are no error and warning from the output

Did you use print debug to find out which code line is not working?

The code is working. But I want to make the server can hear the jumpscare sound

try putting the sound in humanoidrootpart?

since you want server to hear you would have to use serverscript

and you can use remote events to fire when you click button the in server you play sound

1 Like

It works in a local script sounds dont have to be played in server

OP wants it to play in the server.

Ohh sorry then my bad I didn’t know

yea but it will only be heard by the local player if played in server the sound will play for everyone

Wait, can ServerScript work in screengui?

then just play it in a local script ;-; also @ComplicatedParadigm told me it was supposed to be played in the server

not sure about that but you use remote events to fire server

It’s okay, I fixed it O v O. Thanks for helping