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)