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

How do I go about using Network Ownership on welded items?

Asked by 5 years ago

I'm trying to use network ownership to clone items and spawn them in front of players. I can get it to work on bricks but not models that use welds. Any help?

local spawnProp = game.ReplicatedStorage.Remotes.SpawnProp
local coolDown = 0.5

local deb = {}

function getPlrId(targetPlayer)
    local targetPlayer = game.Players:GetUserIdFromNameAsync(targetPlayer)
     return targetPlayer
end

function recSet(plr,PropClone)
        if PropClone:IsA("BasePart") then
            PropClone:SetNetworkOwner(plr)
        elseif PropClone:IsA("Model") then
            for i,v in pairs(PropClone:children()) do
                recSet(plr,v)
            end
        end
end

spawnProp.OnServerEvent:Connect(function(plr, name, lookVector, args)
    print("Processing")
    if deb[plr.Name] ~= nil then
        return
    else
        deb[plr.Name] = 0
    end

    if args["2"] ~= nil then
        local PropClone = game.ServerStorage:FindFirstChild(name):Clone()
        PropClone.Parent = plr.Backpack

        wait(coolDown)
        deb[plr.Name] = nil

        return
    end

    if game.ServerStorage:FindFirstChild(name) ~= nil then
        local PropClone = game.ServerStorage:FindFirstChild(name):Clone()
        if PropClone:IsA("BasePart") then
            PropClone.Anchored = false
            PropClone:SetNetworkOwner(plr)
        elseif PropClone:IsA("Model") then
            for c,v in pairs(PropClone:GetChildren()) do
                if v:IsA("BasePart") then
                    v.Anchored = false
                end
            end
        end
        local PlayerLookVector = lookVector
        local PropSize
        local head = plr.Character:WaitForChild("Head", 2)
        if not head then return end 
        if PropClone:IsA("BasePart") then
            PropSize = PropClone.Size
            PropClone.Position = head.Position + PlayerLookVector + Vector3.new(0,PropSize.Y,0) + Vector3.new(PlayerLookVector.X * PropSize.X,PlayerLookVector.Y * PropSize.Y,PlayerLookVector.Z * PropSize.Z)
        elseif PropClone:IsA("Model") then
            PropSize = PropClone:GetExtentsSize()
            PropClone.Parent = game.Workspace
            PropClone:MoveTo(head.Position + PlayerLookVector + Vector3.new(0,PropSize.Y,0) + Vector3.new(PlayerLookVector.X * PropSize.X,PlayerLookVector.Y * PropSize.Y,PlayerLookVector.Z * PropSize.Z))
        end
        print("Spawning "..PropClone.Name)
        PropClone.Parent = game.Workspace

        if args["1"] ~= nil then
            PropClone:MakeJoints()
        end

        if args["3"] ~= nil then
            local targetPlayer = args["4"]
            local bool,GetPlayer = pcall(getPlrId, targetPlayer)
            if bool then
                local CharAppearence = game.Players:GetCharacterAppearanceAsync(GetPlayer)
                for n,o in pairs(CharAppearence:GetChildren()) do
                    if o.Name == "face" then
                        o.Parent = PropClone.Head
                    else
                        o.Parent = PropClone
                    end
                end

                PropClone:MoveTo(plr.Character.Head.Position + PlayerLookVector + Vector3.new(0,PropSize.Y,0) + Vector3.new(PlayerLookVector.X * PropSize.X,PlayerLookVector.Y * PropSize.Y,PlayerLookVector.Z * PropSize.Z))
            else
                PropClone:Destroy()
            end
        end
    else
        print(name.." wasn't found!")
    end

    wait(coolDown)
    deb[plr.Name] = nil
end)

Answer this question