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

why wont my typewriter update the text value?

so i want to make a typewriter effect and this is the script i have rn

local text = game.ReplicatedStorage.ChatText.Value

script.Parent.Parent.ChatText.Chat.MouseButton1Click:Connect(function()
	for i = 1, #text do
		script.Parent.TextLabel.Text = string.sub(text, 1, i)
		wait(0.04)
	end
end)

but when i change the value then it changes to what it was set before i ran the game and it would never update the value

im not sure what im doing wrong here, can someone help me?

1 answer

You statically reserved the state of the StringValue Object on line 1. You likely think you've made a pointer to the Value property, but that's not what has occurred in this logic, nor could it ever regardless. Simply allocate the StringValue, then refer to it's value within the scope of your callback:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Text = ReplicatedStorage:WaitForChild("ChatText")
--// This is vulnerable to exploitation.

local function Typewrite()
	local TypewriteString = Text.Value
	---------------
	for SubstringIndex = 1, #TypewriteString do
		---------------
		TextLabel.Text = TypewriteString:sub(1, #SubstringIndex)
		---------------
		wait(.04)
	end
end


Chat.MouseButton1Click:Connect(Typewrite)

2 comments

0

my output says: 22:22:22.913 - Players.mynam3with123.PlayerGui.ScreenGui.ShowText.LocalScript:9: attempt to get length of a number value and im not sure what it means by that

0

That means your intended StringValue Object was mistakenly replaced by a NumberValue Instance.

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