Advertisement
Freshbloodb

Untitled

Nov 29th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.24 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. local localPlayer = Players.LocalPlayer
  5. local boxes = {}
  6.  
  7. -- Usar valores globales definidos fuera o valores predeterminados
  8. local Ancho = _G.Ancho or 6
  9. local Altura = _G.Altura or 10
  10. local fixedBoxSize = Vector3.new(Ancho, Altura, 1)
  11.  
  12. local function playerHasItems(player)
  13. local character = player.Character
  14. if not character then return false end
  15.  
  16. if character:FindFirstChildOfClass("Tool") then
  17. return true
  18. end
  19.  
  20. local backpack = player:FindFirstChildOfClass("Backpack")
  21. if backpack and #backpack:GetChildren() > 0 then
  22. return true
  23. end
  24.  
  25. return false
  26. end
  27.  
  28. local function updateBox(player)
  29. if not _G.enablecuadrohit then return end -- Verificar si la funcionalidad está habilitada
  30. if player == localPlayer then return end
  31.  
  32. local character = player.Character
  33. if not character then return end
  34.  
  35. if playerHasItems(player) then
  36. if not boxes[player] then
  37. local box = Instance.new("Part")
  38. box.Anchored = true
  39. box.CanCollide = false
  40. box.Transparency = 0.5
  41. box.Color = Color3.new(1, 0, 0)
  42. box.Size = fixedBoxSize
  43. box.Parent = workspace
  44. boxes[player] = box
  45. end
  46.  
  47. local box = boxes[player]
  48. box.CFrame = character:WaitForChild("HumanoidRootPart").CFrame
  49. else
  50. if boxes[player] then
  51. boxes[player]:Destroy()
  52. boxes[player] = nil
  53. end
  54. end
  55. end
  56.  
  57. local function onPlayerAdded(player)
  58. if player ~= localPlayer then
  59. player.CharacterAdded:Connect(function(character)
  60. character:WaitForChild("HumanoidRootPart")
  61. updateBox(player)
  62. end)
  63.  
  64. player.Backpack.ChildAdded:Connect(function()
  65. updateBox(player)
  66. end)
  67. player.Backpack.ChildRemoved:Connect(function()
  68. updateBox(player)
  69. end)
  70.  
  71. player.CharacterAdded:Connect(function(character)
  72. updateBox(player)
  73. character.ChildAdded:Connect(function(child)
  74. if child:IsA("Tool") then
  75. updateBox(player)
  76. end
  77. end)
  78. character.ChildRemoved:Connect(function(child)
  79. if child:IsA("Tool") then
  80. updateBox(player)
  81. end
  82. end)
  83. end)
  84.  
  85. RunService.Heartbeat:Connect(function()
  86. updateBox(player)
  87. end)
  88. end
  89. end
  90.  
  91. for _, player in ipairs(Players:GetPlayers()) do
  92. onPlayerAdded(player)
  93. end
  94.  
  95. Players.PlayerAdded:Connect(onPlayerAdded)
  96.  
  97. Players.PlayerRemoving:Connect(function(player)
  98. if boxes[player] then
  99. boxes[player]:Destroy()
  100. boxes[player] = nil
  101. end
  102. end)
  103.  
  104. RunService.Heartbeat:Connect(function()
  105. for player, box in pairs(boxes) do
  106. if player.Character then
  107. local humanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
  108. if humanoidRootPart then
  109. box.CFrame = humanoidRootPart.CFrame
  110. end
  111. end
  112. end
  113. end)
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement