HowToRoblox

TalkToNPCScript

Nov 11th, 2019
3,250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.57 KB | None | 0 0
  1. local player = game.Players.LocalPlayer
  2. local npc = workspace:WaitForChild("NPC")
  3. local inputted = script.Inputted.Value
  4. local uis = game:GetService("UserInputService")
  5. local text = "Would you like extra walk speed?"
  6. local length = string.len(text)
  7.  
  8. while wait() do
  9.    
  10.     local magnitude = (npc.HumanoidRootPart.Position - player.Character.HumanoidRootPart.Position).Magnitude
  11.        
  12.     if magnitude < 15 then 
  13.            
  14.         script.Parent.Visible = true
  15.        
  16.         script.Parent.E.MouseButton1Click:Connect(function()
  17.            
  18.             if inputted == true then
  19.                 inputted = false
  20.                
  21.                 script.Parent.Parent.Parent.TalkGui.TalkFrame.Dialogue.Text = ""
  22.                 script.Parent.Parent.Parent.TalkGui.TalkFrame.Visible = true
  23.                
  24.                 for i = 1, length do   
  25.                     script.Parent.Parent.Parent.TalkGui.TalkFrame.Dialogue.Text = text:sub(1, i)
  26.                     wait(0.04)
  27.                 end
  28.             end
  29.         end)
  30.        
  31.         uis.InputBegan:Connect(function(input, processed)
  32.             if input.UserInputType == Enum.UserInputType.Keyboard and inputted == true and input.KeyCode == Enum.KeyCode.E and not processed then
  33.                
  34.                 inputted = false
  35.                
  36.                 script.Parent.Parent.Parent.TalkGui.TalkFrame.Dialogue.Text = ""
  37.                 script.Parent.Parent.Parent.TalkGui.TalkFrame.Visible = true
  38.                
  39.                 for i = 1,length do    
  40.                     script.Parent.Parent.Parent.TalkGui.TalkFrame.Dialogue.Text = text:sub(1, i)
  41.                     wait(0.04)
  42.                 end
  43.             end    
  44.         end)
  45.     else
  46.  
  47.         script.Parent.Visible = false
  48.         script.Parent.Parent.Parent.TalkGui.TalkFrame.Visible = false
  49.     end
  50.    
  51.     if script.Parent.Parent.Parent.TalkGui.TalkFrame.Visible == false then
  52.         inputted = true
  53.     end
  54. end
Add Comment
Please, Sign In to add comment