Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why is this audio not playing after respawning?

This is in a local script in a StarterGui. On the StarterGui I decided to turn off ResetOnSpawn. With this, I had to move some code. Everything works.. except the audio doesn't play after the player dies and respawns. When I put print() around the audio, the script seems to be passing through it just fine, but no audio to be heard. This worked fine before moving some code (I don't have the older code), it worked in Studio and online before.

local TS = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer

local frame = script.Parent
local textLabel = frame:WaitForChild("Message")
local frameGone = TS:Create(frame,TweenInfo.new(6),{BackgroundColor3 = Color3.new(1,1,1); BackgroundTransparency = 1})
local character,blur
local sound = Instance.new("Sound")
sound.SoundId = "rbxassetid://168146979"
sound.Volume = 1
local alive = true

local function onSpawn()
	print("Spawned!")
	for k,v in pairs(workspace.CurrentCamera:GetChildren()) do
		v:Destroy()
	end
	
	blur = Instance.new("BlurEffect")
	blur.Size = 2
	blur.Parent = workspace.CurrentCamera
	
	local sunRay = Instance.new("SunRaysEffect")
	sunRay.Intensity = 0.1
	sunRay.Spread = 0.75
	sunRay.Parent = workspace.CurrentCamera
	
	--sound.Parent = character:WaitForChild("Head")
	--print("Playing...")
	--sound:Play()
	
	delay(0,function()
		frameGone:Play()
		TS:Create(textLabel,TweenInfo.new(12),{TextColor3 = Color3.new(); Size = UDim2.new(0.1,0,0.05,0); TextTransparency = 1}):Play()
	end)
end

delay(0,function()
	while true do
		character = workspace:WaitForChild(player.Name)
		sound.Parent = character:WaitForChild("Head")
		sound.Volume = 1
		game:GetService("ContentProvider"):PreloadAsync({sound})
		sound:Play() -- After looping 2, 3, ... times, No sound comes out of this, only works on the first time for some reason.
		onSpawn()
		character.Humanoid.Died:Wait()
		alive = false
		frame.BackgroundColor3 = Color3.new()
		TS:Create(blur,TweenInfo.new(3),{Size = 56}):Play()
		TS:Create(frame,TweenInfo.new(5),{BackgroundTransparency = 0; BackgroundColor3 = Color3.new()}):Play()
		wait(4)
		sound:Stop()
		sound.Parent = nil
		wait(1)
	end
end)

Any advice would be appreciated, thanks!

2 comments

0

Not smart to put audios inside PlayerGui. They always get messed up.

0

The audio is in the player's head, not in PlayerGui. The local script is inside the PlayerGui.

1 answer

As far as I've experienced, audio automatically reset on player spawn. Try putting them below a Gui object and set its property "ResetOnSpawn" to false.

1 comment

0

I changed ResetOnSpawn to false and moved the code to adapt to the change. That's when I had the audio issue

This discussion is preserved as it was. New answers, comments, and votes are closed.