Advertisement
Guest User

NPC Selection

a guest
Mar 31st, 2020
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. local function NPCSelection(NPC)
  2.     if InteractingWithNPC == false then
  3.         InteractingWithNPC = true
  4.        
  5.         local NPCData = NPCsLibrary[NPC]
  6.         local CurrentIndex = 1
  7.        
  8.         local function UpdateMessage(Index)
  9.             NPCTextBox.NPCText.Text = ""
  10.    
  11.             for i = 1, #NPCData.Chats[Index].Message do
  12.                 NPCTextBox.NPCText.Text = NPCData.Chats[Index].Message:sub(1, i)
  13.    
  14.                 if NPCData.Chats[1].Message:sub(i, i) == " " then
  15.                     Sounds.Click:Play()
  16.                 end
  17.                
  18.                 if InRadiusWithNPC == false then
  19.                     for i = 1,10 do
  20.                         NPCTextBox.BackgroundTransparency = NPCTextBox.BackgroundTransparency + 0.07
  21.                         NPCTextBox.NPCName.TextTransparency = NPCTextBox.NPCName.TextTransparency + 0.1
  22.                         NPCTextBox.NPCName.TextStrokeTransparency = NPCTextBox.NPCName.TextStrokeTransparency + 0.1
  23.                         NPCTextBox.NPCText.TextTransparency = NPCTextBox.NPCText.TextTransparency + 0.1
  24.                         NPCTextBox.NPCName.Underline.BackgroundTransparency = NPCTextBox.NPCName.Underline.BackgroundTransparency + 0.1
  25.                         wait()
  26.                     end
  27.                    
  28.                     NPCTextBox.NPCName.Text = ""
  29.                     NPCTextBox.NPCText.Text = ""
  30.                     InteractingWithNPC = false
  31.                     return
  32.                 end
  33.                    
  34.                 wait()
  35.             end
  36.            
  37.             local PositionIndex = 0
  38.             for i,v in pairs(NPCData.Chats[Index].Options) do
  39.                 PositionIndex = PositionIndex + 1
  40.                
  41.                 local OptionButton = Extra.Option:Clone()
  42.                 OptionButton.Name = i
  43.                 OptionButton.Text = i
  44.                 OptionButton.Visible = true
  45.                 OptionButton.Parent = NPCTextBox.Buttons
  46.                 OptionButton:TweenPosition(UDim2.new(0.01,0,((PositionIndex - 1)*.35) + 0.125), "Out", "Back", 1, true)
  47.                 wait(0.35)
  48.             end
  49.         end
  50.        
  51.         NPCTextBox.Buttons.ChildAdded:Connect(function(Button)
  52.             Button.MouseButton1Click:Connect(function()
  53.                 print(CurrentIndex, Button.Name, NPCData.Chats[CurrentIndex].Options[Button.Name])
  54.                 if NPCData.Chats[CurrentIndex].Options[Button.Name] ~= "Cancel" then
  55.                     for i,v in pairs(NPCTextBox.Buttons:GetChildren()) do
  56.                         v:Destroy()
  57.                     end
  58.                     print(1)
  59.                     UpdateMessage(NPCData.Chats[CurrentIndex].Options[Button.Name])
  60.                     CurrentIndex = CurrentIndex + 1
  61.                 else
  62.                     spawn(function()
  63.                         for i,v in pairs(NPCTextBox.Buttons:GetChildren()) do
  64.                             v:Destroy()
  65.                         end
  66.                     end)
  67.                    
  68.                     for i = 1,10 do
  69.                         NPCTextBox.BackgroundTransparency = NPCTextBox.BackgroundTransparency + 0.07
  70.                         NPCTextBox.NPCName.TextTransparency = NPCTextBox.NPCName.TextTransparency + 0.1
  71.                         NPCTextBox.NPCName.TextStrokeTransparency = NPCTextBox.NPCName.TextStrokeTransparency + 0.1
  72.                         NPCTextBox.NPCText.TextTransparency = NPCTextBox.NPCText.TextTransparency + 0.1
  73.                         NPCTextBox.NPCName.Underline.BackgroundTransparency = NPCTextBox.NPCName.Underline.BackgroundTransparency + 0.1
  74.                         wait()
  75.                     end
  76.                    
  77.                     NPCTextBox.NPCName.Text = ""
  78.                     NPCTextBox.NPCText.Text = ""
  79.                     InteractingWithNPC = false
  80.                     InRadiusWithNPC = false
  81.                     NPCInRadius = ""
  82.                     CurrentIndex = 1
  83.                 end
  84.             end)
  85.         end)
  86.        
  87.         UpdateMessage(1)
  88.     end
  89. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement