Audio part script not working

I put it in StarterCharacterScripts AND StarterPlayerScripts

No, nonono. That’s not what I told you to do.
I meant replace workspace.Folder.Obby.Start.BaseStart with workspace.Folder.Obby.Start:WaitForChild("BaseStart")
And for the audio, you only need to do workspace.Folder.Sounds:WaitForChild("BaseSound").

The error is happening because Luau is saying that it will probably wait forever for BaseStart to exist as a child of workspace, because it won’t.

The print is just a way to know if the script is actually detecting the touch. Run the game, and touch the part, then check the output. If it says “Part touched!” then the script detects the part touch. If it says “Playing sound” then the script is playing the sound. If you still don’t hear it, then it’s something with the sound.

1 Like
local playing = false

print("Script ready")

workspace.Folder.Obby.Start:WaitForChild("BaseStart").Touched:Connect(function(hit)
	print("Part touched!")
	if hit.Parent:FindFirstChild("Humanoid") and (not playing) then
		print("Playing sound")
		workspace.Folder.Sounds:WaitForChild("BaseSound"):Play()
		playing = true
		workspace.Folder.Sounds:WaitForChild("BaseSound").Ended:Wait()
		playing = false
	end
end)

it says this: Playing sound - Client - LocalScript:8
12:55:08.975 :arrow_forward: Part touched! (x2) - Client - LocalScript:6
12:55:09.540 Playing sound - Client - LocalScript:8
12:55:10.123 Part touched! - Client - LocalScript:6
12:55:10.123 Playing sound - Client - LocalScript:8
12:55:10.340 Part touched! - Client - LocalScript:6
12:55:10.340 Playing sound - Client - LocalScript:8
12:55:10.656 Infinite yield possible on ‘Workspace.Folder.Sounds:WaitForChild(“BaseSound”)’ - Studio

nothing is playing

I have to go for a little now, but try that.
I would suggest replacing those :WaitForChild() lines with variables too, sorry I didn’t mention that earlier.

local baseStart = workspace.Folder.Obby.Start:WaitForChild("BaseStart")
local baseSound = workspace.Folder.Sounds:WaitForChild("BaseSound")

baseStart.Touched:Connect(function(hit)
    ...
end)

Script works, just seems like the sound doesn’t exist anymore. Did you move it?


Nope

Script works just fine for me.

Try sending me the project file with just the scripts and the other items that the script uses, not the entire project.

how are u using the script?? Where did you put it?

It is problem in core(means in Roblox), i seen many people got this error already.

Though its about Gui, not sound.

heres my project:

Can you copy and past the script over?

local playing = false

print("Script ready")

workspace.Folder.Start:WaitForChild("BaseStart").Touched:Connect(function(hit)
	print("Part touched!")
	if hit.Parent:FindFirstChild("Humanoid") and (not playing) then
		print("Playing sound")
		workspace.Folder.Sounds:WaitForChild("BaseSound"):Play()
		playing = true
		workspace.Folder.Sounds:WaitForChild("BaseSound").Ended:Wait()
		playing = false
	end
end)

Is your volume on?If you just forgot to turn on volume then :skull::skull::skull:

relax, lol. it is on full volume. I am applying the script rn

Again, I suggest storing those instances in variables, so the code is much more maintainable.

like this? local playing = false

print("Script ready")

workspace.Folder.Start:WaitForChild("BaseStart").Touched:Connect(function(hit)
	print("Part touched!")
	if hit.Parent:FindFirstChild("Humanoid") and (not playing) then
		print("Playing sound")
		workspace.Folder.Sounds:WaitForChild("BaseSound"):Play()
		playing = true
		workspace.Folder.Sounds:WaitForChild("BaseSound").Ended:Wait()
		playing = false
	end
end)