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

How would I update this status bar like a typing animation?

Asked by 6 years ago

So I have a String value in ReplicatedStorage. The goal is to update the gui and make it say the string value. I'm trying to make it like it is typing the value by itself. This is the code I have but It is only printing one letter everytime the string value changes.

local status = game.ReplicatedStorage:WaitForChild("StatVal")

function statUpdate()
    local val = status.Value
local letter = nil
    for i = 0,string.len(val) do 
        letter = string.sub(val,i,i) 
        script.Parent.Text = letter
    end
end

status.Changed:Connect(statUpdate)
0
I'm pretty sure lua substrings start at 1 so ignore the i = 0 4d61736f6e 59 — 6y

1 answer

Log in to vote
0
Answered by
Avigant 2374 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

String indexes begin at 1. We also have the # operator in Lua, which can tell us the number of bytes in a string.

for i = 1, #val do
    local letter = val:sub(i, i)
    script.Parent.Text = script.Parent.Text .. letter
end

You're setting the text to the new letter, but we want to use the .. concatenation operator to create a new string, made by glueing one string to another.

1
Thank you so much concatenation completely left my mind and thanks for teaching me about the # operator :) 4d61736f6e 59 — 6y
Ad

Answer this question