Help to add a repeated typing sound to my typewriting gui

Your putting the clone into the torso, so basically the script is copying the sound from replicatedStorage and is putting it in torso but not removing the original from replicatedstorage and then in one second the game.Debris will destroy the clone.

Is it suppose to look like this?
image

Yes, make sure that you define torso is correctly but if you did than that script should work

how do I define torso correctly?

local Torso = Player.Character:WaitForChild(“Torso”) if your using r15 do HumanoidRootPart instead of torso, also looks like you have a syntax error, so try to find that place lol

I just do

SoundEffect = soundObjectReference
local meta = SoundEffect:Clone()
meta.PlayOnRemove = true
meta.Parent = Gui 
meta:Destroy()

Game.Debris is a lot better than using Destroy, since it uses the old remove.

Also I forgot to add to that script, add soundClone.Playing = true

whatever floats your boat, but i’m not sure how game.Debris is better, could you link an article or something

No the text still types with no sound for some reason


I think it might be something to do with the Soundeffect not being told when to play later on in the script

Basically, it helps so you don’t have to use delay, and also if the object is destroy before :Destroy() goes off then it will respond with an error, unlike Debris which is smoother imo, but won’t cause the script to stop if the sound is not there

Lol sorry, you can delete soundClone:play(), if you want, when are you calling the function?

I want to call the function when the text starts to play. when the text stops i want the sound to stop too

So, to play a function you need to call it like this
SoundEffect() do this everytime they type

1 Like

YES!
THANK YOU SO MUCH I HAVE SPENT ALL DAY! You are a genius xD

The article never says how game.Debris is better, or that Destroy() uses an old remove method, it’s basically saying use both methods sparingly depending on the situation, game.Debris is for destroying objects with a limited lifetime, and Destroy() for instantaneous removal. In my use case Destroy() was appropriate because there wasn’t a reason to yield also I’m pretty sure game.Debris calls the Destroy() methods on objects internally

I don’t want to debate, in this thread but so you know, when you use wait it pauses the whole script, when you use delay it makes a new thread, you don’t want that, it will also cause and error if the sound was already destroy, so game.Debris should be used if a object has a lifetime, which a sound object doesn’t really need but it’s a better habit to start using game.Debris.

re-read my code, there’s no need for any kind of yielding or lifetime, PlayOnRemove allows you to destroy the sound object instantaneously and still have playback

I’m just saying you delete out the part where I said the sound object doesn’t need a lifetime…