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

Typewriter effect running on click event?

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

local clickdetector = script.Parent:WaitForChild("ClickDetector")

clickdetector.MouseClick:Connect(function()
	game.StarterGui.Typewritertext.TalkingText.Text = "This is simply, a test."
for i = 1, #text do
    script.Parent.Parent.Dialog.TextLabel.Text = string.sub(text, 1, i)
    wait(0.04)

end
	
	
	
end)

Thank you!

1 comment

0

whats the problem? this looks like it would work.

1 answer

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:

local Players = game:GetService("Players")
local ClickDetector = script.Parent:WaitForChild("ClickDetector")

Players.PlayerAdded:Connect(function(Player)
    local PlayerGui = Player:WaitForChild("PlayerGui")
    ClickDetector.MouseClick:Connect(function()
        --// From this point use PlayerGui.Typewritertext
    end)
end)

1 comment

0

Would that be for the entire thing or only the area in which the event script is triggered?

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