Advertisement
XxxLloyd061302xxX

Keybind Script [LocalScript]

Jul 18th, 2018
7,522
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.04 KB | None | 0 0
  1. local UIS = game:GetService("UserInputService") -- Service used to get the key pressed by a player
  2.  
  3. UIS.InputBegan:connect(function(input,gameProcessed)
  4.     if input.UserInputType == Enum.UserInputType.Keyboard then -- Checks if the player uses a Keyboard
  5.         if input.KeyCode == Enum.KeyCode.E then -- Checks if the player pressed the "E" key
  6.             if UIS:GetFocusedTextBox() == nil then -- Checks if the player is typing on a textbox like the chat... If not then...
  7.                 for i,v in pairs(game.Workspace.NPCs:GetChildren()) do -- Finds all the children from the folder. In this case it will find all the NPCs
  8.                     local mag = (v.Torso.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
  9.                     if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then
  10.                         --Effect XD
  11.                         for i = 1,0.6,-0.05 do
  12.                             wait()
  13.                             script.Parent.ImageColor3 = Color3.new(i,i,i)
  14.                         end
  15.                         wait()
  16.                         for i = 0.6,1,0.05 do
  17.                             wait()
  18.                             script.Parent.ImageColor3 = Color3.new(i,i,i)
  19.                         end
  20.                         --This effect is like when you pressed a button it will darken.
  21.                         v.NPCTalk:FireServer()
  22.                     end
  23.                 end
  24.             end
  25.         end
  26.     end
  27. end)
  28.  
  29. while wait() do
  30.     script.Parent.Visible = false -- Makes it invisible on screen
  31.     for i,v in pairs(game.Workspace.NPCs:GetChildren()) do -- Finds all the children from the folder. In this case it will find all the NPCs
  32.         local mag = (v.Torso.Position-game.Players.LocalPlayer.Character.HumanoidRootPart.Position).magnitude -- Makes a variable for the position between the character and the npc.
  33.         if mag <= 10 then -- If the magnitude is less than or equal to 10 studs then
  34.             local WSP = game.Workspace.CurrentCamera:WorldToScreenPoint(v.Torso.Position) -- The position of the NPC's Torso to 2d
  35.             script.Parent.Visible = true
  36.             script.Parent.Position = UDim2.new(0,WSP.X,0,WSP.Y)
  37.             script.Parent.TextLabel.Text = "to chat with "..v.Name -- Refreshes the text and puts the name of the npc
  38.         end
  39.     end
  40. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement