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

If my Music isn't playing, what should I edit to fix it?

I'm making a Self-Destruct System for my new game, but the music isn't playing when ordered and the output isn't saying anything. Here is the code I tried:

--Functions--
function MakeTextVisible()
	script.TextTransparency.Value = 0.9
	wait(0.05)
	script.TextTransparency.Value = 0.8
	wait(0.05)
	script.TextTransparency.Value = 0.7
	wait(0.05)
	script.TextTransparency.Value = 0.6
	wait(0.05)
	script.TextTransparency.Value = 0.5
	wait(0.05)
	script.TextTransparency.Value = 0.4
	wait(0.05)
	script.TextTransparency.Value = 0.3
	wait(0.05)
	script.TextTransparency.Value = 0.2
	wait(0.05)
	script.TextTransparency.Value = 0.1
	wait(0.05)
	script.TextTransparency.Value = 0
end

function MakeTextInvisible()
	script.TextTransparency.Value = 0.1
	wait(0.05)
	script.TextTransparency.Value = 0.2
	wait(0.05)
	script.TextTransparency.Value = 0.3
	wait(0.05)
	script.TextTransparency.Value = 0.4
	wait(0.05)
	script.TextTransparency.Value = 0.5
	wait(0.05)
	script.TextTransparency.Value = 0.6
	wait(0.05)
	script.TextTransparency.Value = 0.7
	wait(0.05)
	script.TextTransparency.Value = 0.8
	wait(0.05)
	script.TextTransparency.Value = 0.9
	wait(0.05)
	script.TextTransparency.Value = 1
end


--Script--
script.Parent.MouseClick:Connect(function(click)
	if script.Running.Value == false and script.Parent.Parent.Parent.CoreComputer.SurfaceGui.Computer.PowerStatus.Power.Value == 100 then
		script.Clicker.Value = click.Name
		local Time = math.random(1,70)
		local Song = math.random(1,1)
		workspace.ControlRods.Height.Value = -73
		wait(0.25)
		workspace.ControlRods.Height.Value = -72
		wait(0.25)
		workspace.ControlRods.Height.Value = -71
		wait(0.25)
		workspace.ControlRods.Height.Value = -70
		wait(0.25)
		workspace.ControlRods.Height.Value = -69
		workspace.CoreComputer.SurfaceGui.Computer.ControlRods.Text = "Control Rods Active: 0/126"
		workspace.Alarms.EmergencyLight1.Alarm1:Play()
		wait(2)
		workspace.Alarms.EmergencyLight1.Announcement:Play()
		wait(2.25)
		game.SoundService.SelfDestruct.Song1:Play()
		MakeTextVisible()
		wait(0.1)
		script.Narration.Value = script.Clicker.Value.." has activated the Energy Core Self Destruct System!"
		wait(3)
		MakeTextInvisible()
		wait(0.1)
		script.Narration.Value = "An Escape Helicopter has landed on the Mountain! Find it to Escape the Self-Destruct System!"
		wait(0.1)
		MakeTextVisible()
		wait(3)
		script.Narration.Value = "Facility about to Explode; escape Helicopter leaves in "..Time.." seconds!"
		repeat
		    wait(1)
		    Time = Time -1
		    script.Narration.Value = "Facility about to Explode; escape Helicopter leaves in "..Time.." seconds!"
		until Time == 0
		script.Narration.Value = "Escape Helicopter is leaving!"
		MakeTextInvisible()
		game.SoundService.SelfDestruct.PrimarySongs.Song1.Volume = 0.4
		wait(0.25)
		game.SoundService.SelfDestruct.PrimarySongs.Song1.Volume = 0.3
		wait(0.25)
		game.SoundService.SelfDestruct.PrimarySongs.Song1.Volume = 0.2
		wait(0.25)
		game.SoundService.SelfDestruct.PrimarySongs.Song1.Volume = 0.
		wait(0.25)
		game.SoundService.SelfDestruct.PrimarySongs.Song1.Volume = 0
	end
end)

Don't worry about it all, all I want you to worry about is line 67, aka, this line:

game.SoundService.SelfDestruct.Song1:Play()

I would appreciate some help! Thanks! -JBennettChief9

1 answer

Improvements

Use GetService for the Sound Service

Use local variables in order to reduce the amount of code you have rewrite

Use for loops for constant increments (takes up less lines)

Use WaitForChild to make sure an instance exists before using it

Issues

In the entirety of the script, "Song1" is found under SelfDestruct.PrimarySongs.Song1, but in line 67, there is no "PrimarySongs"

Also, I'm not sure how TextTransparency is set up for you. If you were altering a specific text, then there is no need for the .Value, but if the script has a StringValue named "TextTransparency" under it, then those lines are fine (otherwise, the ancestry is wrong as a script has no TextTransparency property)

The WaitForChild calls set in the below revision should show up in the output if either the ancestry is wrong or the item has not loaded yet

Revised Server Script

--Variables--
local detector = script.Parent
local height = workspace:WaitForChild("ControlRods"):WaitForChild("Height")
local running = script:WaitForChild("Running")
local clicker = script:WaitForChild("Clicker")
local power = detector.Parent.Parent:WaitForChild("CoreComputer"):WaitForChild("SurfaceGui"):WaitForChild("Computer"):WaitForChild("PowerStatus"):WaitForChild("Power")
local light = workspace:WaitForChild("Alarms"):WaitForChild("EmergencyLight1")
local rods = workspace:WaitForChild("CoreComputer"):WaitForChild("SurfaceGui"):WaitForChild("Computer"):WaitForChild("ControlRods")
local song = game:GetService("SoundService"):WaitForChild("SelfDestruct"):WaitForChild("PrimarySongs"):WaitForChild("Song1")
local narration = script:WaitForChild("Narration")

--Functions--
function MakeTextVisible()
	for a = 1, 0, -0.1 do
		script.TextTransparency.Value = a
		wait(0.05)
	end
end

function MakeTextInvisible()
	for b = 0, 1, 0.1 do
		script.TextTransparency.Value = b
		wait(0.05)
	end
end


--Script--
detector.MouseClick:Connect(function(click)
	if running.Value == false and power.Value == 100 then
		clicker.Value = click.Name
		local Time = math.random(1,70)
		local Song = math.random(1,1)
		height.Value = -73
		wait(0.25)
		height.Value = -72
		wait(0.25)
		height.Value = -71
		wait(0.25)
		height.Value = -70
		wait(0.25)
		height.Value = -69
		rods.Text = "Control Rods Active: 0/126"
		light:WaitForChild("Alarm1"):Play()
		wait(2)
		light:WaitForChild("Announcement"):Play()
		wait(2.25)
		song:Play()
		MakeTextVisible()
		wait(0.1)
		narration.Value = clicker.Value.." has activated the Energy Core Self Destruct System!"
		wait(3)
		MakeTextInvisible()
		wait(0.1)
		narration.Value = "An Escape Helicopter has landed on the Mountain! Find it to Escape the Self-Destruct System!"
		wait(0.1)
		MakeTextVisible()
		wait(3)
		narration.Value = "Facility about to Explode; escape Helicopter leaves in "..Time.." seconds!"
		repeat
			wait(1)
			Time = Time - 1
			narration.Value = "Facility about to Explode; escape Helicopter leaves in "..Time.." seconds!"
		until Time == 0
		narration.Value = "Escape Helicopter is leaving!"
		MakeTextInvisible()
		for c = 0.5, 0, -0.1 do
			song.Volume = c
			wait(0.25)
		end
	end
end)

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