Advertisement
Guest User

Script

a guest
Sep 17th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2. local rs = game:GetService("ReplicatedStorage")
  3. local event = rs:WaitForChild("toolEvent") -- <
  4.  
  5. local plr = game.Players.LocalPlayer
  6. local kg = plr.PlayerGui:WaitForChild("keyGui")
  7. local char = plr.Character
  8.  
  9. function search()
  10. local tools = workspace:WaitForChild("tools"):GetChildren()
  11. local min = nil
  12. local tool = nil
  13.  
  14. for i = 1, #tools do
  15. local handle = tools[i]:FindFirstChild("Handle")
  16. if handle then
  17. local mag = (char.HumanoidRootPart.Position-handle.Position).magnitude
  18. if min == nil or mag < min then
  19. min = mag
  20. tool = tools[i]
  21. end
  22. end
  23. end
  24.  
  25. if min then
  26. if min < 5 then
  27. return tool
  28. end
  29. end
  30. end
  31.  
  32. uis.InputBegan:Connect(function(input, gameProcessed)
  33. if input.UserInputType.Name == "Keyboard" and gameProcessed == false then
  34. if input.KeyCode.Name == "E" then
  35. local tool = search()
  36. if tool then
  37. event:FireServer(tool)
  38. kg.E.Visible = false
  39. end
  40. end
  41. end
  42. end)
  43.  
  44. while wait(1) do
  45. local tool = search()
  46. if tool then
  47. kg.E.Visible = true
  48. else
  49. kg.E.Visible = false
  50. end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement