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

why wont my typewriter update the text value?

Asked by 4 years ago
Edited 4 years ago

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

1local text = game.ReplicatedStorage.ChatText.Value
2 
3script.Parent.Parent.ChatText.Chat.MouseButton1Click:Connect(function()
4    for i = 1, #text do
5        script.Parent.TextLabel.Text = string.sub(text, 1, i)
6        wait(0.04)
7    end
8end)

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

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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:

01local ReplicatedStorage = game:GetService("ReplicatedStorage")
02 
03local Text = ReplicatedStorage:WaitForChild("ChatText")
04--// This is vulnerable to exploitation.
05 
06local function Typewrite()
07    local TypewriteString = Text.Value
08    ---------------
09    for SubstringIndex = 1, #TypewriteString do
10        ---------------
11        TextLabel.Text = TypewriteString:sub(1, #SubstringIndex)
12        ---------------
13        wait(.04)
14    end
15end
16 
17 
18Chat.MouseButton1Click:Connect(Typewrite)
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 mynam3with123 65 — 4y
0
That means your intended StringValue Object was mistakenly replaced by a NumberValue Instance. Ziffixture 6913 — 4y
Ad

Answer this question