Audio part script not working

I tried them and they didn’t work.


The color is yellow on the second line as shown in the photo above.

It’s yellow because “playing” is not an assigned variable. To solve this, in the first line put:

playing = false

Put it in the line before the Touched event.

1 Like

I can’t but the local script in the WorkSpace so then how do I make it reffer back to the part I have? I changed the name to the part but it still didn’t work.

That’s not yellow, and you didn’t even hover over it? It’s a bad idea to ignore errors like this.

playing = false
workspace.BaseStart.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") and (not playing) then
		workspace.Folder.Sounds.BaseSound:Play()
		playing = true
		workspace.Folder.Sounds.BaseSound.Ended:Wait()
		playing = false
	end
end)

Nothing shows if I hover over it.

BaseStart isn’t a valid child of workspace from what I saw in the Explorer, you need to change your path in the 2nd line.

workspace isn’t affected if you changed the parent of the script, which means it’s okay to just move it into StarterGui and change nothing about it

It is I think. I changed the name of the Base-Start to BaseStart

I tested this out and the script still didn’t work/

No, that’s not it. BaseStart isn’t a direct child of workspace.

image

Instead of workspace.BaseStart, you need to do workspace.Folder.Obby.Start.BaseStart.

1 Like

I fixed anything that might be causing the error, but it is still not working. I have it in StarterGui

StarterGui is a poor place to put it, it doesn’t need anything related to GUI. Not that it affects the issue at hand.
Remember to keep checking the Output for any errors, and make sure you don’t have “illegal” characters in your instance names (e.g. a whitespace, or symbols)
Show the script and the entire Workspace in the Explorer again.

I did that and it is
not working. Here is how everything looks like.

this is how the audio looks like:

Add a print statement to each indent in the function, and outside the function (e.g. "Script ready" after the function, "Part touched!" in the first line of the function, and "Playing sound" after you set playing to true)
Make sure canTouch is true on the part.
One more thing that I should mention, try replacing .BaseStart with :WaitForChild("BaseStart") in the first line, and do the same with the sound (:WaitForChild("BaseSound"))

2 Likes
local AreaSounds = Instance.new("Sound", script)
AreaSounds.Looped = true
local plr = script.Parent
local Presser = plr:WaitForChild("HumanoidRootPart")
local DifferentAreas = workspace:WaitForChild("Areas")
local CurrentArea = nil

game:GetService("RunService").Heartbeat:Connect(function()
 local raycast = Ray.new(Presser.Position, Presser.CFrame.UpVector * -1000)
 local part = workspace:FindPartOnRayWithWhitelist(raycast, {DifferentAreas})
 if part and part.Parent == DifferentAreas then
  if part ~= CurrentArea then
   CurrentArea = part
   AreaSounds.SoundId = CurrentArea.Sound.SoundId
   AreaSounds:Play()
  end 
 else
  CurrentArea = nil
  AreaSounds:Stop()
 end
end)

–This script would work, but with some changed applied.

I tried that and it is just showing errors.

local playing = false

print("Script ready")

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

–Error: Infinite yield possible on ‘Workspace:WaitForChild(“BaseStart”)’