Hasli4

Untitled

Apr 10th, 2026
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2.  
  3. local tool = script.Parent
  4. local handle = tool:WaitForChild("Handle")
  5.  
  6. local pickedUp = false
  7. local touchConn
  8.  
  9. local function playerHasKey(player)
  10. local backpack = player:FindFirstChild("Backpack")
  11. local character = player.Character
  12.  
  13. if backpack and backpack:FindFirstChild(tool.Name) then
  14. return true
  15. end
  16.  
  17. if character and character:FindFirstChild(tool.Name) then
  18. return true
  19. end
  20.  
  21. return false
  22. end
  23.  
  24. local function onTouched(hit)
  25. if pickedUp then
  26. return
  27. end
  28.  
  29. local character = hit.Parent
  30. if not character then
  31. return
  32. end
  33.  
  34. local humanoid = character:FindFirstChildOfClass("Humanoid")
  35. if not humanoid then
  36. return
  37. end
  38.  
  39. local player = Players:GetPlayerFromCharacter(character)
  40. if not player then
  41. return
  42. end
  43.  
  44. pickedUp = true
  45.  
  46. if touchConn then
  47. touchConn:Disconnect()
  48. end
  49.  
  50. if playerHasKey(player) then
  51. tool:Destroy()
  52. return
  53. end
  54.  
  55. tool.Parent = player:WaitForChild("Backpack")
  56. script:Destroy()
  57. end
  58.  
  59. touchConn = handle.Touched:Connect(onTouched)
Advertisement
Add Comment
Please, Sign In to add comment