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

Using a local script to clone objects from lighting?

Asked by 6 years ago

So I'm making a character selection GUI, and am using local scripts, it works perfectly in 'play solo' but in game or via the network. Other characters can not see the morphed character, only the local user can. I tried using a server side script, but obviously that won't work in a startergui (as far as I aware). Any work arounds or fixes?

local Character = player.Character
script.Parent.MouseButton1Down:connect(onTouched)
function onTouched(hit)
    if Character:findFirstChild("Humanoid") ~= nil and Character:findFirstChild("Chest") == nil then
        local g = game.lighting.Character.Chest:clone()
        g.Parent = Character
        local C = g:GetChildren()
        for i=1, #C do
            if C[i].className == "Part" then
                local W = Instance.new("Weld")
                W.Part0 = g.Middle
                W.Part1 = C[i]
                local CJ = CFrame.new(g.Middle.Position)
                local C0 = g.Middle.CFrame:inverse()*CJ
                local C1 = C[i].CFrame:inverse()*CJ
                W.C0 = C0
                W.C1 = C1
                W.Parent = g.Middle
            end
                local Y = Instance.new("Weld")
                Y.Part0 = Character.Torso
                Y.Part1 = g.Middle
                Y.C0 = CFrame.new(0, 0, 0)
                Y.Parent = Y.Part0
        end

        local h = g:GetChildren()
        for i = 1, # h do
            if h[i].className == "Part" then
                h[i].Anchored = false
                h[i].CanCollide = false
            end
        end
    elseif Character:findFirstChild("Chest") ~= nil then
        Character:findFirstChild ("Chest"):remove ("Chest")
        end
end 

script.Parent.MouseButton1Down:connect(onTouched)
0
What type of errors are you getting? Meltdown81 309 — 6y
0
Use remote events and do the changes server side MooMooThalahlah 421 — 6y
0
Cloning on a client is not recommended. Use a server script and a RemoteEvent. LeadRDRK 437 — 6y

Answer this question