Sungmingamerpro13

LocalScript of Dialogue (STORY GAME)

Mar 9th, 2024
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 1.09 KB | Source Code | 0 0
  1. local player = game.Players.LocalPlayer
  2. local CreateDialogueEvent = game.ReplicatedStorage.CreateDialogueEvent
  3. local DialogueFrame = player.PlayerGui.ScreenGui.Frame
  4.  
  5. local function playSound(sound_id) -- Plays typing sound
  6.     local sound = Instance.new("Sound",game.ReplicatedStorage)
  7.     sound.SoundId = sound_id
  8.     sound.Volume = .1
  9.     sound.PlayOnRemove = true
  10.     sound:Destroy()
  11. end
  12.  
  13. local function textAnimate(content) -- Animates each letter
  14.     for i=1,string.len(content) do
  15.         DialogueFrame.TextLabel.Text = string.sub(content,1,i)
  16.         playSound("rbxassetid://915576050")
  17.         if string.sub(content,i,i) == "!" or string.sub(content,i,i) == "." or string.sub(content,i,i) == "?" then
  18.             wait(1)
  19.         elseif  string.sub(content,i,i) == "," then
  20.             wait(.5)
  21.         else
  22.             wait(.05)
  23.         end
  24.     end
  25. end
  26.  
  27. CreateDialogueEvent.OnClientEvent:Connect(function(image_id, content) -- activates when called from the Server
  28.     if not player:findFirstChild("secretEnding") then
  29.         DialogueFrame.ImageLabel.Image = image_id
  30.         DialogueFrame.TextLabel.Text = ""
  31.         DialogueFrame.Visible = true
  32.         textAnimate(content)
  33.     end
  34. end)
Add Comment
Please, Sign In to add comment