How to make AlvinBlox's Typewriting effect restart everytime i open the gui

Im trying to make a tool that pull up a gui, which is working but when i try use the typewriting effect, it works the first time but then it stays as done and not redoing it i used alvinblox’s script as i’m a very new beginner.

local TextLable = script.Parent:WaitForChild("Main"):WaitForChild("Text")
local player = game.Players.LocalPlayer
local Frame = player.PlayerGui.EatFruitGui.Main
local Yes = Frame.Yes
local No = Frame.No
local TypeSound = script.TypingSound


local function TypeWriteEffect(object,text)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		TypeSound:Play()
		wait(0.05)
	end
end



	
repeat
if Frame.Visible == true then
    
	end	
	task.wait()
until Frame.Visible == true

	TypeWriteEffect(TextLable,"Do You Want To Eat This Fruit?")

any ideas?

1 Like
local TextLable = script.Parent:WaitForChild("Main"):WaitForChild("Text")
local player = game.Players.LocalPlayer
local Frame = player.PlayerGui.EatFruitGui.Main
local Yes = Frame.Yes
local No = Frame.No
local TypeSound = script.TypingSound


local function TypeWriteEffect(object,text)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		TypeSound:Play()
		wait(0.05)
	end
end

Frame:GetPropertyChangedSignal("Visible"):Connect(function()
	TypeWriteEffect(TextLable,"Do You Want To Eat This Fruit?")
end)

You should add an If statement to check if it is indeed visible.

if Frame.Visible  == true then
TypeWriteEffect(TexLable, "YoourTextiSoGood")
end

Its playing Even tho i clicked no. Im tryna make it so if you click no then click on the tool again it will play the text is playing even tho the gui is not open.

Ive done that in the code but it doesnt repeat for some reason

Could we see your full code?

Thanks.

Set the text to nothing when you close it

1 Like

Oh for the tool as well? ok.
‘’’
local Player = game.Players.LocalPlayer
repeat task.wait() until Player.Character
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character:WaitForChild(“Humanoid”)

local Frame = Player.PlayerGui.EatFruitGui.Main
local Yes = Frame.Yes
local No = Frame.No

local EatAnim = script:WaitForChild(“Eat”)
local EatAnimTrack = humanoid.Animator:LoadAnimation(EatAnim)

local DevilFruits = game.ReplicatedStorage.DevilFruits
local currentTool = script.Parent
local Toolname = “Rubber”

local function GiveTool(Player)
Frame.Visible = true
local character = currentTool.Parent
local playerWhoEquippedTool = game.Players:GetPlayerFromCharacter(character)
Yes.MouseButton1Click:wait()
EatAnimTrack:Play()
humanoid.WalkSpeed = 0
wait(3.5)
script.Parent:Destroy()
if not playerWhoEquippedTool.Backpack:FindFirstChild(Toolname) then
local Tool = game.ReplicatedStorage.DevilFruits[Toolname]:clone()
Tool.Parent = playerWhoEquippedTool.Backpack
humanoid.WalkSpeed = 16
else
No.MouseButton1Click:wait()
end
end
currentTool.Activated:Connect(GiveTool)
‘’’

I just tried that, It just still stays at Do you want to Eat this fruit?

Maybe try task.wait() it waits till the function is done and then continues

Where tho?

ignore this text its just to fill the 30 letters

Just for future reference, an even easier way to do this would be through the MaxVisibleGraphemes property. This property allows you to control how many characters are displayed. A primary use case for it is specifically typewriting effects.

That’s also a good idea, it’s easier then using string.sub and stuff!

1 Like

Can you use sound with it? also Ive found the fix the new code is


local TextLable = script.Parent:WaitForChild("Main"):WaitForChild("Text")

local player = game.Players.LocalPlayer

local Frame = player.PlayerGui.EatFruitGui.Main

local Yes = Frame.Yes

local No = Frame.No

local TypeSound = script.TypingSound

local DevilFruit = game.StarterPack["Gomu Gomu No Mi"]

local function TypeWriteEffect(object,text)

for i = 1,#text,1 do

object.Text = string.sub(text,1,i)

TypeSound:Play()

wait(0.05)

end

end

repeat

repeat

TypeWriteEffect(TextLable,"")

if Frame.Visible == true then

end

task.wait()

until Frame.Visible == true

TypeWriteEffect(TextLable,"Do You Want To Eat This Fruit?")

task.wait()

No.MouseButton1Click:wait()

until DevilFruit == nil

:D

Yes, this is simply just another property like Text is a property. Sounds and anything else is completely irrelevant.

You can use it in your TypeWriteEffect function like so:

local function TypeWriteEffect(object,text)
    -- Set new label text
    object.Text = text

    -- Loop through the number of characters in the text
    for i=1, #text do
        object.MaxVisibleGraphites = i
        TypeSound:Play()

        task.wait(0.05)
    end
end

For a more in-depth tutorial on typewriter effects, check out the UI Animations tutorial on the Developer Hub.

Sorry, I went to sleep, Thanks very much I will use this next time I get the chance to.

Never heard of it before, Is it new?