Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Players = game:GetService("Players")
- local RunService = game:GetService("RunService")
- -- Function to replicate an instance and its children
- local function replicateInstance(instance)
- if instance:IsA("Instance") then
- local clone = instance:Clone()
- clone.Parent = workspace
- return clone
- end
- end
- -- Function to recursively replicate all children of an instance
- local function replicateAllChildren(instance)
- for _, child in pairs(instance:GetChildren()) do
- local clonedChild = replicateInstance(child)
- if clonedChild then
- replicateAllChildren(clonedChild)
- end
- end
- end
- -- Function to listen for changes in a player's character
- local function listenForChanges(player)
- if player.Character then
- -- Replicate existing instances
- for _, child in pairs(player.Character:GetChildren()) do
- local clonedChild = replicateInstance(child)
- if clonedChild then
- replicateAllChildren(clonedChild)
- end
- end
- -- Listen for new instances added to the character
- player.Character.ChildAdded:Connect(function(child)
- local clonedChild = replicateInstance(child)
- if clonedChild then
- replicateAllChildren(clonedChild)
- end
- end)
- end
- end
- -- Function to set up listeners for all players
- local function setupListeners()
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= Players.LocalPlayer then
- player.CharacterAdded:Connect(function()
- listenForChanges(player)
- end)
- if player.Character then
- listenForChanges(player)
- end
- end
- end
- Players.PlayerAdded:Connect(function(player)
- player.CharacterAdded:Connect(function()
- listenForChanges(player)
- end)
- end)
- end
- -- Initialize listeners
- setupListeners()
- -- Continuously check for new instances
- RunService.RenderStepped:Connect(function()
- for _, player in pairs(Players:GetPlayers()) do
- if player ~= Players.LocalPlayer and player.Character then
- for _, child in pairs(player.Character:GetChildren()) do
- local clonedChild = replicateInstance(child)
- if clonedChild then
- replicateAllChildren(clonedChild)
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement