Sound doesn't always play with :Play()

Hello, i am coding a fighting system and i am using a punch sound when the punch hits, except that it doesnt always play all the time when i click

Heres the code

				local punch = game:GetService("SoundService").Folder.punch:Clone()
				punch.PlaybackSpeed = math.random(0.7,1.4)
				punch.Parent = player.Character.UpperTorso
				punch:Play()
				game:GetService("Debris"):AddItem(punch,2)

Please help me!

Edit : I did preload every asset in the game before lauching it

The code is correct assuming you have something to trigger this code. i believe you do since you say that it does work from time to time. But just to be sure could you show the whole script? Or at least the function where this code is located?

1 Like

Here it is :


hitbox.Touched:Connect(function(hit, hum)
			if hum.Parent.Name == player.Character.Name then
			else
				hum:TakeDamage(7)
				local hit = hum:LoadAnimation(script.hitByPunch)
				hit.Priority = Enum.AnimationPriority.Action
				hit:Play(.05)

				local punch = game:GetService("SoundService").Folder.punch:Clone()
				punch.PlaybackSpeed = math.random(0.7,1.4)
				punch.Parent = player.Character.UpperTorso
				punch:Play()
				game:GetService("Debris"):AddItem(punch,2)

				local punchPARTICLE = game:GetService("ReplicatedStorage").circle.Attachment.ParticleEmitter:Clone()
				punchPARTICLE.Parent = hum.Parent:FindFirstChild("UpperTorso")
				punchPARTICLE:Emit(1)
				game:GetService("Debris"):AddItem(punchPARTICLE,2)
			end
			print(hit)

		end)

Sorry for the weird variable names, i must mention that everything else works.

nvm i should have read what you said after

1 Like

Yes, remember that the sound plays but not always

Are there any errors or warnings in the output?

1 Like

No, there are not

there are not there are not

I am not sure what might be causing it at this point but i am fairly certain its not a scripting issue

1 Like

programming WHAT?!

honestly, even though i don’t have any code suggestions

why clone the sound? why not just have it stored somewhere and then simply use it? like the humanoid rootpart, for example

1 Like

Thats a good idea, i’ll try that

Thank you… It works… I’m forever Grateful!

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