How do I add a sound effect for every letter a player chats?

  • So I wanted to try to make a script wherein if someone types, for example, a player types “Hi” each letter will be counted as numbers and play a sound, in that case “Hi” would have 2 letters and 2 sounds. The sound I’m adding for every letter

  • I cannot seem to make it no matter how hard I think of it, I am no where even a decent player with knowledge so that is why I seek help here, here is it in action in one of the games I’ve found it in. Video of the thing I’m trying to accomplish.

  1. I’ve tried doing this since it’s the only thing I can think of and my skill is utter garbage.
game.Players.PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		for i = 1,#msg do
			sound:Play()
		end
		
	end)
end)

I would love this to be solved since I’m still learning and I hope to learn more!

3 Likes

What is not working, the script seems ok. Do you want the sound played for everyone or just the player?

1 Like

I wanted it to be played for everyone.

1 Like

The “#” works on strings as well not only arrays.

2 Likes

So what is the issue with the script?, your post is very vague.

1 Like

The problem in your script was that the sound was playing over and over, with no time to actually play. This causes the sound to not even actually sound like it’s playing.

What also matters is where the sound you’re referencing is located, as far as I know, sounds are only able to play when they’re parented under Workspace.

Here, I have modified your script and parented it under workspace. (Don’t do this, please keep your scripts sorted in the services Roblox has created) It now will wait for the entire sound to play with a bit extra of a delay since scripts don’t execute immediately.

Hope this helps!

local sound = script.Sound
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Chatted:Connect(function(msg)
		for i = 1,#msg do
			sound:Play()
			wait(sound.TimeLength / 2)
		end
	end)
end)

Edit: Ignore the “message heard!” part, I used it for testing.

Edit 2: After using the same audio as you did, I’m switching the script a little for it to sound less choppy.

Edit 3: Sorry for my ignorance, I realized a bit ago that sounds also play in GUIs.

6 Likes

If anyone needs to play a sound while a player is actively typing,

Baseplate.rbxl (19.3 KB)

you could hook up a GetPropertyChangedSignal for the chat bar (TextBox object) so that whenever a player types, it plays a sound:

-- LocalScript @ StarterPlayerScripts
local player = game.Players.LocalPlayer
local chat = player.PlayerGui:WaitForChild("Chat")
local bar = chat.Frame.ChatBarParentFrame:FindFirstChild("ChatBar", true)
local sound = script.Sound -- a sound parented to this

local function play()
	sound:Play()
end

bar:GetPropertyChangedSignal("Text"):Connect(play)

You could even use UserInputService and play a sound if the engine has acted on the input:

local UserInputService = game:GetService("UserInputService")
local sound = script:WaitForChild("Sound")

local function onInput(_, typing)
	if typing then
		sound:Play()
	end
end

UserInputService.InputBegan:Connect(onInput)

You can wait for a sound to finish playing before playing it again by yielding though Sound.Ended:Wait() .

Alternatively you could fork the ChatBar module.

6 Likes