Sound stuck with IsPlaying Value True, but never actually plays the sound

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:

image

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.

1 Like

The problem might be with your playback speed formula.

I don’t think you can use decimals there.

try

math.random(9,11)/10
				local Sounds = game.ReplicatedFirst.Sounds
				local HitSFX = Sounds.HitM1:Clone()
				HitSFX.PlaybackSpeed = math.random(9, 11)/10
				HitSFX.Parent = humanoidRootPart
				HitSFX.PlayOnRemove = true
				HitSFX:Destroy()
				script:Destroy()

the random cant have decimals so just divide by 10 after
play on remove also

2 Likes

try replace this ( math.random cannot random miliseconds for random ( if you set 0.9 - 1.1 it only set automatic playbackspeed 0 - 1 )
HitSFX.PlaybackSpeed=Random.new():NextNumber(.9,1.1)

Check output careful there different

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