Sound not playing

okay, so, i’m making a horror game, and there’s a section that a set of planks are blocking you way, and you need to destroy them to continue and this script makes so that each set of planks get destroyed one by one, but for some reason the sound that is on a folder on sound service doesen’t play when it’s supposed to.

Please take note that i’m not expecienced in scripting so this script it’s pretty simple and if you try to help try to keep it simple so that i can understand.

------------------------------------------------------------script---------------------------------------------------------------------

local planks = script.Parent.Parent.Parent
local promt = script.Parent
local sound = game.SoundService:WaitForChild("Sounds").Swing
local plank1 = planks:WaitForChild("Plank1")
local plank2 = planks:WaitForChild("Plank3")
local plank3 = planks:WaitForChild("Plank5")
local Waittime = 2

promt.Triggered:Connect(function()
	promt.Enabled = false
	sound:Play()
	plank1.CanCollide = false
	plank1.Anchored = false
	wait(Waittime)
	sound:Play()
	plank2.CanCollide = false
	plank2.Anchored = false
	wait(Waittime)
	sound:Play()
	plank3.CanCollide = false
	plank3.Anchored = false
	planks.Barrier:Destroy()
	wait(3)
	planks:Destroy()
end)

Thank you if anyone wants to help

1 Like

Are there any errors? You didn’t use WaitForChild with Swing. I would also recommend cloning the sound into the actual parts, that way the sound comes from them rather than everywhere at once. Lastly, you would use task.wait() as it supersedes wait() and is more accurate.

2 Likes

You should use game:GetService("SoundService"), a good rule of thumb is to never directly reference a service.

1 Like

What’s the properties of the sound? Any errors in the output?

You could try putting the sound into a part near the planks. That way it plays from that part.
You would have to make the rolloffmode linear instead of inverse. Inverse would play the sound louder the further you’re away from it.

1 Like

Particularly useful if you plan on obfuscating Service Names.
@puppetgames1508 , here are some things I recommend.

  • Try print debugging - see if lines are running as intended, etc.
  • Recheck the sound properties - are they as intended?
  • While you play the game, is the sound Instance still there? Is it really quiet? etc…
  • Use task.wait(Waittime) instead of just wait(Waittime)
  • Try spacing out your code a bit more and adding some comments so the logic follows through - perhaps it’s a Logic Error (unlikely, though)?
  • Is it being run on the server or locally - perhaps this would help to pinpoint exactly what might be wrong?
1 Like

Does the sound play, but just not at the correct time?

maybe use this:

local planks = script.Parent.Parent.Parent
local promt = script.Parent
local SoundService  = game:GetService("SoundService")
SoundService:WaitForChild("Sounds")
local Sounds = SoundService:FindFirstChild("Sounds")
Sounds:WaitForChild("Swing")
local sound = Sounds:FindFirstChild("Swing")
local plank1 = planks:WaitForChild("Plank1")
local plank2 = planks:WaitForChild("Plank3")
local plank3 = planks:WaitForChild("Plank5")
local Waittime = 2
promt.Disabled = false

promt.Triggered:Connect(function()
	promt.Disabled = true
	sound:Play()
	plank1.CanCollide = false
	plank1.Anchored = false
	wait(Waittime)
	sound:Play()
	plank2.CanCollide = false
	plank2.Anchored = false
	wait(Waittime)
	sound:Play()
	plank3.CanCollide = false
	plank3.Anchored = false
	planks.Barrier:Destroy()
	wait(3)
	planks:Destroy()
end)

You sugestion worked as well, but i can’t give 2 solutions

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.