Advertisement
AnonymousJG179

TEST

Jul 10th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. local Players = game:GetService("Players")
  2. local RunService = game:GetService("RunService")
  3.  
  4. -- Function to replicate an instance and its children
  5. local function replicateInstance(instance)
  6. if instance:IsA("Instance") then
  7. local clone = instance:Clone()
  8. clone.Parent = workspace
  9. return clone
  10. end
  11. end
  12.  
  13. -- Function to recursively replicate all children of an instance
  14. local function replicateAllChildren(instance)
  15. for _, child in pairs(instance:GetChildren()) do
  16. local clonedChild = replicateInstance(child)
  17. if clonedChild then
  18. replicateAllChildren(clonedChild)
  19. end
  20. end
  21. end
  22.  
  23. -- Function to listen for changes in a player's character
  24. local function listenForChanges(player)
  25. if player.Character then
  26. -- Replicate existing instances
  27. for _, child in pairs(player.Character:GetChildren()) do
  28. local clonedChild = replicateInstance(child)
  29. if clonedChild then
  30. replicateAllChildren(clonedChild)
  31. end
  32. end
  33. -- Listen for new instances added to the character
  34. player.Character.ChildAdded:Connect(function(child)
  35. local clonedChild = replicateInstance(child)
  36. if clonedChild then
  37. replicateAllChildren(clonedChild)
  38. end
  39. end)
  40. end
  41. end
  42.  
  43. -- Function to set up listeners for all players
  44. local function setupListeners()
  45. for _, player in pairs(Players:GetPlayers()) do
  46. if player ~= Players.LocalPlayer then
  47. player.CharacterAdded:Connect(function()
  48. listenForChanges(player)
  49. end)
  50. if player.Character then
  51. listenForChanges(player)
  52. end
  53. end
  54. end
  55. Players.PlayerAdded:Connect(function(player)
  56. player.CharacterAdded:Connect(function()
  57. listenForChanges(player)
  58. end)
  59. end)
  60. end
  61.  
  62. -- Initialize listeners
  63. setupListeners()
  64.  
  65. -- Continuously check for new instances
  66. RunService.RenderStepped:Connect(function()
  67. for _, player in pairs(Players:GetPlayers()) do
  68. if player ~= Players.LocalPlayer and player.Character then
  69. for _, child in pairs(player.Character:GetChildren()) do
  70. local clonedChild = replicateInstance(child)
  71. if clonedChild then
  72. replicateAllChildren(clonedChild)
  73. end
  74. end
  75. end
  76. end
  77. end)
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement