Advertisement
Tinybang_Studio

TypeWriterAPI

May 5th, 2020
2,087
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. local SOURCE_LOCALE = "en"
  2.  
  3. local LocalizationService = game:GetService("LocalizationService")
  4. local Players = game:GetService("Players")
  5.  
  6. local player = Players.LocalPlayer
  7.  
  8. local translator = nil
  9. pcall(function()
  10. translator = LocalizationService:GetTranslatorForPlayerAsync(player)
  11. end)
  12. if not translator then
  13. pcall(function()
  14. translator = LocalizationService:GetTranslatorForLocaleAsync(SOURCE_LOCALE)
  15. end)
  16. end
  17.  
  18. local TypeWriter = {}
  19.  
  20. local defaultConfigurations = {
  21. delayTime = 0.2,
  22. extraDelayOnSpace = true
  23. }
  24.  
  25. function TypeWriter.configure(configurations)
  26. for key, value in pairs(defaultConfigurations) do
  27. local newValue = configurations[key]
  28. if newValue ~= nil then
  29. defaultConfigurations[key] = newValue
  30. else
  31. warn(key .. " is not a valid configuration for TypeWriter module")
  32. end
  33. end
  34. end
  35.  
  36. function TypeWriter.typeWrite(guiObject, text,prop)
  37. prop = prop or "Text"
  38. guiObject.AutoLocalize = false
  39. guiObject[prop] = ""
  40. local displayText = text
  41. if translator then
  42. displayText = translator:Translate(guiObject, text)
  43. end
  44. for first, last in utf8.graphemes(displayText) do
  45. local grapheme = string.sub(displayText, first, last)
  46. guiObject[prop] = guiObject[prop] .. grapheme
  47. if defaultConfigurations.extraDelayOnSpace and grapheme == " " then
  48. wait(defaultConfigurations.delayTime)
  49. end
  50. wait(defaultConfigurations.delayTime)
  51. end
  52. end
  53.  
  54. return TypeWriter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement