Dialogue System

So, I made a Dialogue script with animated text, And How do i add system like if theres a “.” or “,” in the dialouge text it will pause for 0.5 - 1 seconds?

The script :

local Player = game.Players.LocalPlayer

local DialougeEvent = game.ReplicatedStorage.RemoteEvents.GuiEvents.DialougeEvent
local Frame = Player.PlayerGui:WaitForChild("DialougeGui").Frame

local function AnimateText(Dialouge)
	for i = 1, #Dialouge, 1 do
		Frame:WaitForChild("DialougeLabel").Text = string.sub(Dialouge, 1, i)
		script.Parent.Sound:Play()
		wait(0.3)
	end
end

DialougeEvent.OnClientEvent:Connect(function(PlayerImage, PlayerName, Dialouge)
	Frame.Visible = true
	Frame:WaitForChild("NameLabel").Text = PlayerName
	Frame:WaitForChild("ImageLabel").Image = PlayerImage
	AnimateText(Dialouge)
end)

You could get the current char like this:

--// example
string.sub(string, i, i)

You would basically use that line to get the current character and check if it’s a period or a comma. And here’s a way you could apply it…

if string.sub(Dialouge, i, i) == "." then
   task.wait(…)
   elseif string.sub(Dialouge, i, i) == "," then
      task.wait(…)
end

I’ll leave it up to you to find out where to put it since I don’t really feel like writing more (shouldn’t be too complicated tho)

Also just being a little nitpicky but ya spelled Dialog (or Dialogue if you prefer the non-American spelling) wrong… yeah idk why I added this part lol

Thanks it worked! (and I just realized that I misspelled the word “Dialogue” lol)

1 Like

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