Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Parts duplicating nonstop after check if it's not a certain name?

Asked by 3 years ago

Title, I'm trying to make a method that replicates my body C0 and C1 positions along with any other parts to the server. if you want me to explain better: When a part is made on the client, it checks if it's not or does not have "ServerReplicatedPart" in it, and if it doesn't, it makes it on the server with active updates of the CFrame and size, name, color, etc... If you need, I can supply any of the necessary scripts for the RemoteFunctions.

local chr = game:GetService("Players").LocalPlayer.Character
repeat wait() until chr.Torso:FindFirstChild("Neck") ~= nil

game:GetService("RunService").RenderStepped:Connect(function()
    game:GetService("ReplicatedStorage").Body:FireServer({
        RS = chr.Torso["Right Shoulder"].C0,
        LS = chr.Torso["Left Shoulder"].C0,
        RH = chr.Torso["Right Hip"].C0,
        LH = chr.Torso["Left Hip"].C0,
        N = chr.Torso["Neck"].C0,
        R = chr.HumanoidRootPart["RootJoint"].C0
    },
    {
        RS = chr.Torso["Right Shoulder"].C1,
        LS = chr.Torso["Left Shoulder"].C1,
        RH = chr.Torso["Right Hip"].C1,
        LH = chr.Torso["Left Hip"].C1,
        N = chr.Torso["Neck"].C1,
        R = chr.HumanoidRootPart["RootJoint"].C1
    })
end)

print("Loading...")
script.Parent.DescendantAdded:Connect(function(p)
    if p:FindFirstChild("ServerReplicatedPart") == nil and p.Name ~= "ServerReplicatedPart" then
        p2=game:GetService("ReplicatedStorage").Create:InvokeServer(p.ClassName,p.Parent:GetFullName())
        p2.CanCollide = false
        p.Changed:Connect(function(prop)
            game:GetService("ReplicatedStorage").Change:InvokeServer(p2,prop,p[prop])
        end)
        if p2:IsA("BasePart") then
            repeat wait()
                if p2:IsA("BasePart") then
                    game:GetService("ReplicatedStorage").Change:InvokeServer(p2,"CFrame",p.CFrame)
                end
            until p2==nil
        end
    end
end)
script.Parent.DescendantRemoving:Connect(function(p)
    if p:FindFirstChild("ServerReplicatedPart") == nil and p.Name ~= "ServerReplicatedPart" then
        game:GetService("ReplicatedStorage").Removee:InvokeServer(p:GetFullName())
    end
end)
print("Loaded!")

Answer this question