Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do you measure the lengh of the chat?

Asked by 5 years ago

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)
0
You measured it correctly? `length` should be the number of characters in the message. However this does include spaces. chomboghai 2044 — 5y
0
Yeah Thats what Im trying to do Sergiomontani10 236 — 5y
0
Spaces dont really matter Sergiomontani10 236 — 5y
0
If you want to pass the length of the string, just FireClient(#msg) Amiaa16 3227 — 5y
View all comments (2 more)
0
Alright how would I make it that each string adds 0.2 seconds to the wait time Sergiomontani10 236 — 5y
0
Let me just post the full script for a better understanding Sergiomontani10 236 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago

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)
Ad
Log in to vote
0
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago
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.

0
Still cant figure it out. Should I use wait(time)? Sergiomontani10 236 — 5y
0
You would have to continuously play the animation until the time is over. chomboghai 2044 — 5y
0
Still aint working, it wont even receive the server firing the client Sergiomontani10 236 — 5y
0
use print statements to find the earliest point that the script stops working. then let me know chomboghai 2044 — 5y

Answer this question