Hasli4

Untitled

Apr 10th, 2026
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. -- NightSpawnerEvent.lua
  2. -- Положить в ServerScriptService
  3.  
  4. local ServerStorage = game:GetService("ServerStorage")
  5. local Lighting = game:GetService("Lighting")
  6. local Workspace = game:GetService("Workspace")
  7.  
  8. local MODELS_FOLDER_NAME = "Monster7" -- проверьте точное имя папки
  9. local KEY_TEMPLATE_NAME = "Key" -- Tool в ServerStorage
  10.  
  11. local function isNight(clockTime)
  12. return clockTime > 0 and clockTime < 6
  13. end
  14.  
  15. local modelsFolder = ServerStorage:FindFirstChild(MODELS_FOLDER_NAME)
  16. if not modelsFolder then
  17. warn("NightSpawnerEvent: папка '" .. MODELS_FOLDER_NAME .. "' не найдена в ServerStorage.")
  18. return
  19. end
  20.  
  21. local keyTemplate = ServerStorage:FindFirstChild(KEY_TEMPLATE_NAME)
  22. if not keyTemplate then
  23. warn("NightSpawnerEvent: Tool '" .. KEY_TEMPLATE_NAME .. "' не найден в ServerStorage.")
  24. return
  25. end
  26.  
  27. local function setupMonster(monster)
  28. if not monster:IsA("Model") then
  29. return
  30. end
  31.  
  32. local humanoid = monster:FindFirstChildOfClass("Humanoid")
  33. if not humanoid then
  34. return
  35. end
  36.  
  37. humanoid.Died:Connect(function()
  38. local key = keyTemplate:Clone()
  39. key.Parent = Workspace
  40.  
  41. local handle = key:FindFirstChild("Handle")
  42. if not handle or not handle:IsA("BasePart") then
  43. warn("У Tool '" .. KEY_TEMPLATE_NAME .. "' нет Handle.")
  44. key:Destroy()
  45. return
  46. end
  47.  
  48. local rootPart = monster:FindFirstChild("HumanoidRootPart") or monster.PrimaryPart
  49. if not rootPart then
  50. rootPart = monster:FindFirstChildWhichIsA("BasePart")
  51. end
  52.  
  53. if rootPart then
  54. handle.CFrame = rootPart.CFrame * CFrame.new(math.random(-3, 3), 2, math.random(-3, 3))
  55. else
  56. handle.CFrame = CFrame.new(monster:GetPivot().Position + Vector3.new(math.random(-3, 3), 2, math.random(-3, 3)))
  57. end
  58.  
  59. handle.Anchored = false
  60. handle.CanCollide = true
  61. end)
  62. end
  63.  
  64. local function setupMonsterFolder(folder)
  65. for _, obj in ipairs(folder:GetChildren()) do
  66. setupMonster(obj)
  67. end
  68.  
  69. folder.ChildAdded:Connect(function(obj)
  70. setupMonster(obj)
  71. end)
  72. end
  73.  
  74. -- если скрипт запускается уже ночью
  75. local wasNight = isNight(Lighting.ClockTime)
  76.  
  77. if wasNight then
  78. local clone = modelsFolder:Clone()
  79. clone.Name = modelsFolder.Name .. "_clone_" .. tostring(os.time())
  80. clone.Parent = Workspace
  81. setupMonsterFolder(clone)
  82. print("NightSpawnerEvent: немедленное клонирование (скрипт запущен ночью).")
  83. end
  84.  
  85. -- при переходе день -> ночь
  86. Lighting:GetPropertyChangedSignal("ClockTime"):Connect(function()
  87. local ct = Lighting.ClockTime
  88. local nowNight = isNight(ct)
  89.  
  90. if nowNight and not wasNight then
  91. local clone = modelsFolder:Clone()
  92. clone.Name = modelsFolder.Name .. "_clone_" .. tostring(os.time())
  93. clone.Parent = Workspace
  94. setupMonsterFolder(clone)
  95.  
  96. print("NightSpawnerEvent: клонирование выполнено при входе в ночь. (ClockTime = " .. tostring(ct) .. ")")
  97. end
  98.  
  99. wasNight = nowNight
  100. end)
Advertisement
Add Comment
Please, Sign In to add comment