Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SOURCE_LOCALE = "en"
- local LocalizationService = game:GetService("LocalizationService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local translator = nil
- pcall(function()
- translator = LocalizationService:GetTranslatorForPlayerAsync(player)
- end)
- if not translator then
- pcall(function()
- translator = LocalizationService:GetTranslatorForLocaleAsync(SOURCE_LOCALE)
- end)
- end
- local TypeWriter = {}
- local defaultConfigurations = {
- delayTime = 0.2,
- extraDelayOnSpace = true
- }
- function TypeWriter.configure(configurations)
- for key, value in pairs(defaultConfigurations) do
- local newValue = configurations[key]
- if newValue ~= nil then
- defaultConfigurations[key] = newValue
- else
- warn(key .. " is not a valid configuration for TypeWriter module")
- end
- end
- end
- function TypeWriter.typeWrite(guiObject, text,prop)
- prop = prop or "Text"
- guiObject.AutoLocalize = false
- guiObject[prop] = ""
- local displayText = text
- if translator then
- displayText = translator:Translate(guiObject, text)
- end
- for first, last in utf8.graphemes(displayText) do
- local grapheme = string.sub(displayText, first, last)
- guiObject[prop] = guiObject[prop] .. grapheme
- if defaultConfigurations.extraDelayOnSpace and grapheme == " " then
- wait(defaultConfigurations.delayTime)
- end
- wait(defaultConfigurations.delayTime)
- end
- end
- return TypeWriter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement