I’m currently attempting to make a sound play whenever the player hits an enemy, but the sound keeps glitching out in an odd way.
local Sounds = game.ReplicatedFirst.Sounds
local HitSFX = Sounds.HitM1:Clone()
HitSFX.PlaybackSpeed = math.random(0.9, 1.1)
HitSFX.Parent = humanoidRootPart
HitSFX:Play()
--game.Debris:AddItem(HitSFX, 0.6)
wait()
script:Destroy()
This code is taking from ReplicatedFirst, then attaching the sound to the enemy’s HumanoidRootPart to play the sound from there. The whole thing works, but in game the sounds only play about 50% of the time, with the properties of the un-played sounds looking like this:
Properly played sounds in contrast have their PlaybackSpeed set to 0, and the Playing value is set to false as it should be. I cannot tell if this is purely a roblox issue, or a problem on my part.
I have attempted Pre-Loading the sounds, hence their being in ReplicatedFirst along with a script that uses the ContentProvider service to pre-load them.