Hasli4

Untitled

Apr 26th, 2026
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. -- Script внутри детали-переключателя / двери / зоны
  2. local Players = game:GetService("Players")
  3.  
  4. local part = script.Parent
  5. local KEY_NAME = "Key"
  6.  
  7. local debounce = false
  8.  
  9. local function removeKeyFromPlayer(player)
  10. local backpack = player:FindFirstChild("Backpack")
  11. local character = player.Character
  12.  
  13. if backpack then
  14. local key = backpack:FindFirstChild(KEY_NAME)
  15. if key and key:IsA("Tool") then
  16. key:Destroy()
  17. return true
  18. end
  19. end
  20.  
  21. if character then
  22. local key = character:FindFirstChild(KEY_NAME)
  23. if key and key:IsA("Tool") then
  24. key:Destroy()
  25. return true
  26. end
  27. end
  28.  
  29. return false
  30. end
  31.  
  32. part.Touched:Connect(function(hit)
  33. if debounce then return end
  34.  
  35. local character = hit:FindFirstAncestorOfClass("Model")
  36. if not character then return end
  37.  
  38. local player = Players:GetPlayerFromCharacter(character)
  39. if not player then return end
  40.  
  41. debounce = true
  42. removeKeyFromPlayer(player)
  43. task.wait(0.3)
  44. debounce = false
  45. end)
Advertisement
Add Comment
Please, Sign In to add comment