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?
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)