You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
A simple gun system -
What is the issue? Include screenshots / videos if possible!
I press on the mouse to fire, the gun does fires, however as you can see in the following video, the shot noises arrive 0.5-1second after the bullet got fired, even tho when running the code, the sound should arrive first and then the bullet appear (or at least the sound and spawn of the bullet should be at the same time)
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried looking up multiple posts on devforum, and most are about preloading the sound to then clone it, parent it to a sound origin and play it from there. That’s exactly the method I am using but as you can see, it’s not working out as intended (yes yes, sound plays, however reminder that it’s supposed to play at the same time the bullet shoots out, not after, that just takes away from the gameplay immersion)
Concerned snippets of my code (the client: side/local script):
--During the creation of the weapon, that gets made as soon as the weapon arrives in the inventory, meaning by the time you take it out to shoot everything's (animations and sounds too technically) are already loaded
self.PreloadedSounds = {}
self.PreloadedSounds.GunShot = self.Sounds:WaitForChild("GunShot"):Clone()
--During the code block/snippet where the gun shoots the projectile, a few lines before actually shooting the projectile:
self.PreloadedSounds.GunShot.Parent = barrel
self.PreloadedSounds.GunShot:Play()
self.PreloadedSounds.GunShot.Ended:Connect(function()
self.PreloadedSounds.GunShot.Parent = nil
end)
Please any idea would be welcome, I really do not find any solution to this annoying issue (also it’s my first time working with sounds so there might be some crucial beginners rule that I’m somehow not finding online)
P.S.: Before I forget and go to sleep, here is the sound effect I took from the toolbox, it’s 1 second long
the ID: rbxassetid://1905367471
the link: https://create.roblox.com/store/asset/1905367471/Gun-Shot