Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you measure the lengh of the chat?

Basicly I wanna fire the amount of numbers in the chat and for each letter it should add a second to the lengh.

I cant find anything online.

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:Connect(function(msg)
		local length = string.len(msg)
		game.ReplicatedStorage.ChatEvent.ChatAnimation:FireClient()
	end)
end)

6 comments

0

You measured it correctly? length should be the number of characters in the message. However this does include spaces.

0

Yeah Thats what Im trying to do

0

Spaces dont really matter

0

If you want to pass the length of the string, just FireClient(#msg)

0

Alright how would I make it that each string adds 0.2 seconds to the wait time

0

Let me just post the full script for a better understanding

2 answers

Script

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:Connect(function(msg)
		game.ReplicatedStorage.ChatEvent.ChatAnimation:FireClient(#msg)
	end)
end)

LocalScript

repeat
    wait()
until game.Players.LocalPlayer

player = game.Players.LocalPlayer
character = player.Character
if not character then
    character = player.CharacterAdded:wait()
end

humanoid = character:WaitForChild("Humanoid")
s = humanoid:LoadAnimation(game.StarterPack.OnChatAnimation.ChatAnim)

game.ReplicatedStorage.ChatEvent.ChatAnimation.OnClientEvent:Connect(function(msg)
	s:Play(msg)
end)
game.Players.PlayerAdded:connect(function(player)
    player.Chatted:Connect(function(msg)
        game.ReplicatedStorage.ChatEvent.ChatAnimation:FireClient(#msg * 0.2) -- passes in the total length of time
    end)
end)

In the script above, you simply take the number of characters in msg by using the # symbol. Then, multiply that by the amount of time per character.

#msg * 0.2 is 0.2 seconds per character.

Then inside your OnClientEvent:Connect(function()... you can receive the parameter by doing this: OnClientEvent:Connect(function(time)....

Hope this helps.

4 comments

0

Still cant figure it out. Should I use wait(time)?

0

You would have to continuously play the animation until the time is over.

0

Still aint working, it wont even receive the server firing the client

0

use print statements to find the earliest point that the script stops working. then let me know

This discussion is preserved as it was. New answers, comments, and votes are closed.