Typewriting and shaking effect

Ok basically I need like a small text at the bottom that I can set to say whatever I want and it does a typewriting effect but also shakes. The typewriting part should be easy and I found some tutorials on how to make the text shake, the main problem I’m having is:

I don’t know how can I change the text. Like I managed to add a typewriting effect to the shaking (just a simple wait before creating a new TextLabel) but I can’t change the text later. I tried a lot of things but none of them worked.

I basically just need a function that I can call and if I add any text it does the effects. I hope someone can help me with this

1 Like

By shaking the text, do you mean shaking it’s position while the text is being typewrited

Well, If I can make it shake while typewriting it would be better but with this is enough:

The main problem is that yeah, the effect works, but I can’t change it later or make it play when I need it.

1 Like

How did you get the text to shake like that?

1 Like

You can just start the effect while creating each text label.

Here’s an example of what you could do:

local textDisplayed = true
 --I don’t know what loop you’ll use here
    --Your code for creating the text label
    task.spawn(function()
        while textDisplayed == true do
            --Put code here for the shaking effect
        end
    end)
end

task.wait(whateverTime)

textDisplayed = false
1 Like

Here’s the script:

local text = "IM STARVING"
TextFont = Enum.Font.Arcade
TextFontSize = 30
TextSize = game.TextService:GetTextSize(text, TextFontSize, TextFont, Vector2.new(10000,10000))
SpaceAmount = 1.3 -- 1 is the base, with no spacing
TextHolderFrame = Instance.new("Frame")
TextHolderFrame.Parent = script.Parent
TextHolderFrame.Position = UDim2.new(0.5,0,0.5,0)
TextHolderFrame.AnchorPoint = Vector2.new(0.5,0.5)
TextHolderFrame.BackgroundTransparency = 1
TextHolderFrame.BackgroundColor3 = Color3.fromRGB(255,255,255)
TextHolderFrame.BorderSizePixel = 0
TextHolderFrame.Name = "TextHolderFrame"

TextHolderFrame.Size = UDim2.new(0,TextSize.X * SpaceAmount,0,TextSize.Y)

for i = 1, #text do --loop through every character in the text string

	CharacterLabel = Instance.new("TextLabel")

	CharacterLabel.ZIndex = 2
	CharacterLabel.BackgroundTransparency = 1
	CharacterLabel.Font = TextFont
	CharacterLabel.TextSize = TextFontSize
	CharacterLabel.Size = UDim2.new(0,TextSize.X/#text, 0, TextSize.Y) --set the size, based on what GetTextSize returns
	CharacterLabel.Position = UDim2.new(0, ((TextSize.X/#text) * i * SpaceAmount) - TextSize.X/#text/2, 0.5, 0) --calculate the position, by multiplying the size of one character, by the current character index we are on. The Scale values are just to position the text in this middle of the TextHolderFrame, which we will be parenting this label to shortly.
	CharacterLabel.AnchorPoint = Vector2.new(0.5,0.5)
	CharacterLabel.Text = string.sub(text, i, i) --grab just the character we need from the string
	CharacterLabel.TextColor3 = Color3.new(1,0,0)
	CharacterLabel.TextStrokeTransparency = 0
	CharacterLabel.TextStrokeColor3 = Color3.new(0,0,0)

	CharacterLabel.Parent = TextHolderFrame
	wait(.1)
end

--To make the individual TextLabels shake, you can do something like this:

CharacterLabels = script.Parent.TextHolderFrame:GetChildren()

Shake = true
while Shake == true do

	for _, Label in pairs(CharacterLabels) do -- loop through the CharacterLabels one by one

		Label.AnchorPoint = Vector2.new(math.random(4.5, 5.5)/10, math.random(4.5, 5.5)/10) --I'm using AnchorPoint instead of Position so we can maintain the original Position
	end

	wait(0.05)

end

Found it on another devforum post and it works, main problem, I need it as a function but I can’t think of a way to do it, I already tried but it just didn’t work.

1 Like
local text = "IM STARVING"
TextFont = Enum.Font.Arcade
TextFontSize = 30
local function WriteText(text,TextFont,TextFontSize,Frame)
	TextSize = game.TextService:GetTextSize(text, TextFontSize, TextFont, 	Vector2.new(10000,10000))
	SpaceAmount = 1.3 -- 1 is the base, with no spacing
	TextHolderFrame = Instance.new("Frame")
	TextHolderFrame.Parent = script.Parent
	TextHolderFrame.Position = UDim2.new(0.5,0,0.5,0)
	TextHolderFrame.AnchorPoint = Vector2.new(0.5,0.5)
	TextHolderFrame.BackgroundTransparency = 1
	TextHolderFrame.BackgroundColor3 = Color3.fromRGB(255,255,255)
	TextHolderFrame.BorderSizePixel = 0
	TextHolderFrame.Name = "TextHolderFrame"

	TextHolderFrame.Size = UDim2.new(0,TextSize.X * SpaceAmount,0,TextSize.Y)

	for i = 1, #text do --loop through every character in the text string

		CharacterLabel = Instance.new("TextLabel")

		CharacterLabel.ZIndex = 2
		CharacterLabel.BackgroundTransparency = 1
		CharacterLabel.Font = TextFont
		CharacterLabel.TextSize = TextFontSize
		CharacterLabel.Size = UDim2.new(0,TextSize.X/#text, 0, TextSize.Y) --set the size, based on what GetTextSize returns
		CharacterLabel.Position = UDim2.new(0, ((TextSize.X/#text) * i * SpaceAmount) - TextSize.X/#text/2, 0.5, 0) --calculate the position, by multiplying the size of one character, by the current character index we are on. The Scale values are just to position the text in this middle of the TextHolderFrame, which we will be parenting this label to shortly.
		CharacterLabel.AnchorPoint = Vector2.new(0.5,0.5)
		CharacterLabel.Text = string.sub(text, i, i) --grab just the character we need from the string
		CharacterLabel.TextColor3 = Color3.new(1,0,0)
		CharacterLabel.TextStrokeTransparency = 0
		CharacterLabel.TextStrokeColor3 = Color3.new(0,0,0)
		
		CharacterLabel.Parent = TextHolderFrame
		wait(.1)
	end
	CharacterLabels = script.Parent.TextHolderFrame:GetChildren()

	Shake = true
	coroutine.resume(coroutine.create(function()
		while Shake == true do

			for _, Label in pairs(CharacterLabels) do -- loop through the CharacterLabels one by one
				Label.AnchorPoint = Vector2.new(math.random(4.5, 5.5)/10, math.random(4.5, 5.5)/10) --I'm using AnchorPoint instead of Position so we can maintain the original Position
			end

			wait(0.05)

		end
	end))
end

Maybe like this?

3 Likes

Thank you so much, Its exactly what I needed :smiley:

No problem.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.