Local script can't detect an audio inside it

Explorer:
image
Script itself:


Output:
image

The issue happens even after restarting roblox studio.
The only fix is to delete the sound and add a new one under the same name.

1 Like

Have you tried doing script:WaitForChild("Thunder")?

2 Likes

That’s not the problem. The script editor itself can’t detect Thunder even if it exists under the local script.

You can’t put the audio in the LocalScript because it won’t load in properly. You are getting that error because the audio does not even exist when the game starts running. Just put the sound in SoundService and change the script accordingly and you should be good.

Edit: I forgot to mention that this should go in Scripting Support because this isn’t a bug

2 Likes

Hi, the reported behavior is by design. We’re closing this report, but please reach out if you have any additional questions in Scripting Support.

As @DonaldDuck5150 pointed out, sounds should be either global (SoundService) or parented to BaseParts or Attachments.

I Recommend carefully reading the StarterPlayerScripts documentation, especially the part about “It can contain LocalScripts and other objects to be copied to the PlayerScripts container once when a Player joins the game.”

If you look at the error message, you see that the sound is not found under the Players.<yourplayer>.PlayerScripts.LocalScript because of the copy.

The Script Editor itself functions just fine, it does the proper autocomplete suggestion.

I also recommend you read the docs for Sound and the tutorial about audio for better sound effects.

Hope this helps!

1 Like

I think I should have clarified, the main issue was the script editor couldn’t autocomplete when typing “Thunder” manually while I was writing the script. It could autocomplete for other sounds/parts/whatever under the local script just fine, but thunder was messing it up for some reason. Seemed like a bug, but not sure.