I'm right now trying to create a typewriter effect based on a click event in my test roblox game.
I've got the click event pinned down, But I need to know how I can get a typewriter effect working once I click something.
Here is the code I'm using
01 | local clickdetector = script.Parent:WaitForChild( "ClickDetector" ) |
02 |
03 | clickdetector.MouseClick:Connect( function () |
04 | game.StarterGui.Typewritertext.TalkingText.Text = "This is simply, a test." |
05 | for i = 1 , #text do |
06 | script.Parent.Parent.Dialog.TextLabel.Text = string.sub(text, 1 , i) |
07 | wait( 0.04 ) |
08 |
09 | end |
10 |
11 |
12 |
13 | end ) |
Thank you!
The issue is that you’re referencing StarterGui
, a replication container. This is used to form the UI on the server, however, it doesn’t actually belong to the UI that appears in-game. All of it’s content is replicated over to a container in the Player called PlayerGui
. To modify the UI, you must control it from that point of reference.
Try this:
1 | local Players = game:GetService( "Players" ) |
2 | local ClickDetector = script.Parent:WaitForChild( "ClickDetector" ) |
3 |
4 | Players.PlayerAdded:Connect( function (Player) |
5 | local PlayerGui = Player:WaitForChild( "PlayerGui" ) |
6 | ClickDetector.MouseClick:Connect( function () |
7 | --// From this point use PlayerGui.Typewritertext |
8 | end ) |
9 | end ) |