Help to add a repeated typing sound to my typewriting gui

So basically, the texts types out itself (typewriting effect) and I want to add a keyboard key press sound to every letter that is typed. I have made the function but i am not sure if it is correct and I don’t now how to activate it properly. I am bad at scripting lol.

My script:

1 Like

Make it a sound object in replicatedStorage, then place the sound id in the object and change the values you need.

local sound = game.ReplicatedStorage. -- Sound name
local soundClone = sound:Clone()
soundClone.Parent = -- if you want to play for everyone put it in workspace, if you want to play only near the person who plays the sound put it in there torso
soundClone:Play()
game.Debris:AddItem(soundClone, 1)

Put that in your function should work

so do I add that to my sound function in my script? or do i delete the whole function and only put that in the function?

Im so confused so firstly what do you mean sound name? secondly I put the sound in replicated storage? I chose torso so what do I put in the torso?

Oh okay, sorry if I was confusing, let me explain more,
When you create a sound object, you name it, to get it from replicatedStorage you need to call it by it’s name so *game.ReplicatedStorage.(Whatever you name the sound in replicatedStorage), yes you can delete all your code in that function and add that, Sound Objects | Documentation - Roblox Creator Hub if you scroll down in 3d sounds in the article it tells you how to add a sound object, then when your use .Parent that means where the sound is going to go, and the clone makes it so it does destroy the original sound, so it can keep on using it

Oh ok but what did u mean by putting the sound in the torso? If i want to put it in the torso should I remove it from replicated storgae?

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