Hello everyone, how are you doing.
After a lot of failed attempts I decided to create a draft to ask for help.
How do I make a script where if a player says something, a random sound would play. And the amount of times a sound would play depends on the amount of words in a player’s sentence/message. This idea is similar to a game called: generic roleplay gaem. - Roblox.
When you say something in that game, a mumbling noise would play as if the player was actually talking.
I think that this could be a simple solution to your problem:
local sound = ? -- the sound clip object
game.Players.PlayerAdded:Connect(function(player) -- when a player joins
player.CharacterAdded:Connect(function(char) -- when a player's character is loaded into the game
local clone = sound:Clone()
clone.Name = "NAME"
clone.Parent = player.Character.Head
end)
player.Chatted:Connect(function(msg) -- when a player sends a message
local wordCount = #msg:split(" ") -- get the count of words seperated by a SPACE
if player.Character and player.Character.Head:FindFirstChild("NAME") then -- check if the cloned sound still exists
local clone = player.Character.Head:FindFirstChild("NAME")
clone:Play() -- play
task.wait(wordCount) -- play the sound for the amount of words in message
clone:Stop() -- stop the sound
end
end)
end)