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

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

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)

1 comment

0

I'm pretty sure lua substrings start at 1 so ignore the i = 0

1 answer

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 comment

1

Thank you so much concatenation completely left my mind and thanks for teaching me about the # operator :)

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