Code to run music isn't even running? I'm a bit confused as there are scripts to enable it

So essentially, my problem is that my script won’t run and I don’t know why. I have run out of places to look for answers and I ended up here. Its probably a really simple fix but I don’t code often :sob:

The code that won’t run: (Disabled, but enabled by another script after being given to a player)

local val = true

while val == true do
	print("Hi2")
	if script.Parent.Value == true then
		print("Hi")
		for i, v in pairs(script.Parent.Parent.Sounds:GetChildren()) do
			print(v)
			v:Play()
			while wait(v.TimeLength) do
				if script.Parent.Value == false then 
					v:Pause()
					break
				end
			end
		end

	end
	wait()
end

The code that gives the script to the player: (On joining)

game.Players.PlayerAdded:Connect(function(plr)
	local clone1 = game.ReplicatedStorage.TitleScreen:Clone()
	clone1.Parent = plr
	if clone1.InMenu.Value == true then
		clone1.InMenu.Music.Enabled = true
	end
end)

Screenshot 2024-06-20 115824

Is Hi2 or Hi or v being printed?

For your first script what is the code that Enables it? Your issue could be there as well.

Printing a word like Hi tells you if that section of code is working, but you need to find out why the code is working.
The best way I’ve found for troubleshooting is to print the variable you are checking before all your if checks. Imagine you did

if not x then 
    print("x = false")

Well if x is nil then that code will print that it’s false, which is incorrect.

For example instead of just

	if script.Parent.Value == true then

put

    print(script.Parent.Value)
	if script.Parent.Value == true then

That way if Value prints nil or something else you don’t expect then you can backtrack to find out why the variable isn’t what you think it should be.

1 Like

I tend to use the print statements as checks to see if the code is running as it should, the problem itself is that the print statements are not doing anything. That would mean that the entire script isn’t running in the first place.

The code that enables the local script that should be playing the music lies in a regular script inside replicated storage. This is the code that enables it:

clone1.InMenu.Music.Enabled = true

What i’m confused about isn’t with what the value is doing, as it says true when printed, but in the fact that the local script is not running. Is there something I need to do to make the script run after enabling it??

Also, Im printing Hi, Hi2, and v all as checks in the code to see if it is running correctly.

1 Like

I think its definitely something I need to do to make the script run once its enabled, is there anything I can do to make that happen?? :sob:

You said “Also, Im printing Hi, Hi2, and v all as checks in the code to see if it is running correctly.” but you didn’t answer the question about whether or not they are printing in the Output window. That would tell us more information.

My point is you can check with printed words to see if code IS running, but that doesn’t tell you why sections don’t run.
1 print statement before the if with that information is waaay more helpful than 1 print telling you it did happen.

I’ve rarely seen people use Enabled to run a script, so I’m not too familiar with it. Why not just keep the script Enabled with a Function to check for a change in script.Parent.Value that only fires if the Value changes and if it does then run the code.

#################

Oh jeez. I just looked closer at your last screenshot. Sounds only play in the Workspace, in a BasePart, or from an Attachment, not from folders.

oh-
wait so how do I get it to play???

the sounds need to be specific to the player, and each player’s camera is far away from their character-

ah I fixed it, it was a different issue

Please don’t just post ‘I fixed it’.
It may help others in the forums that have a similar issue to know exactly what you did that solved it.