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

Short Way To Set A String Value?

now i saw this question about an hour ago and it had this script going that constantly changed a text with like 3 lines of code for each character of the string but i was wondering because i believe there is a way to do a loop until a string value equals another string value the scirpt i was looking at was this

Script:

local function Choosen(chosen)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. "."
    wait(2)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. "."
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". "
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". T"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Tr"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Tru"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Trut"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth "
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth o"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or "
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or D"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or Da"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or Dar"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or Dare"
    wait(0.1)
    game.Players.LocalPlayer.PlayerGui.Dialog.Frame.Text.Text = chosen .. ". Truth or Dare?"
    game.ReplicatedStorage.Dialogg7:FireServer(chosen)
end

and i was thinking something like

Script:

local string = "Truth or Dare?"
local text = Player.PlayerGuit.Dialog.Frame.Text.Text
-- iterate through the string value here with a small delay between each character (mabye with a for loop or a repeat until??)
--set the text value as the string value gets read

1 answer

✓ Accepted answer

Like you suggested, there is a much better way to implement this kind of typing effect in Roblox. The key is to use string.sub, which allows you to get parts of a string.

So:

local function Chosen(chosen)
	local textLabel = Player.PlayerGui.Dialog.Frame.Text
	local text = "Truth or Dare?"
	local length = string.len(text)

	for stop = 1, length do
		wait(0.1)
		textLabel.text = string.sub(text, 1, stop)
	end

	game.ReplicatedStorage.Dialogg7:FireServer(chosen)
end

1 comment

0

thanks a lot man a knew there had to be a way!

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