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

Weld script doesn't work in Workspace? [Not Answered!]

Asked by 9 years ago

So I try and clone this Camera into game.Workspace, And when ever I test this in Solo Mode via Studio it works perfectly but in Server's it wont work. I've tried some prints for debugging and it seems that the Weld Script won't work in the Workspace. Any help?

-- By xImmortalChaos--
local Previous = nil

function Weld(Objects)
    for i,v in pairs(Objects:GetChildren()) do
        if v:IsA("Part") or v:IsA("UnionOperation") then
            if Previous ~= nil then
                local Weld = Instance.new("Weld", Previous)
                Weld.Part0 = Previous
                Weld.Part1 = v
                Weld.C0 = Previous.CFrame:inverse() 
                Weld.C1 = v.CFrame:inverse()
            end
            Previous = v
        end
    end
    for i,v in pairs(Objects:GetChildren()) do
        if v:IsA("Part") or v:IsA("UnionOperation") then
            v.Anchored = false
        end
    end
    script:Destroy()
end

Weld(script.Parent)

The Script that clones the hole model into game.Workspace, Well not into game.Workspace it clones the model into a Player's current camera.

wait(1)
local Player = game.Players.LocalPlayer
repeat wait() until game.Workspace:FindFirstChild(Player.Name)
local Character = Player.Character
local Camera = game.Workspace.CurrentCamera

Camera:ClearAllChildren()

--Player.CameraMode = "LockFirstPerson"

local NewModel = Instance.new("Model", Camera)
local Humanoid = Instance.new("Humanoid", NewModel)
local Arm = Character["Right Arm"]:Clone()
Arm.Parent = NewModel
local BodyColors = Instance.new("BodyColors", NewModel)
BodyColors.RightArmColor = BrickColor.new("Pastel brown")
Arm.CanCollide = true
local ModelCamera = game.Lighting.Camera:Clone()
ModelCamera.Parent = NewModel

function WeldCamera()
    local Weld = ModelCamera.Handle:FindFirstChild("ArmWeld")
    if not Weld then
        Weld = Instance.new("Weld", ModelCamera.Handle)
        Weld.Name = "ArmWeld"
        Weld.Part0 = ModelCamera.Handle
        Weld.Part1 = Arm
    end
    Weld.C0 = CFrame.new(0.8, 0.8, 0) * CFrame.Angles(0, math.pi/2, 0)
end

function WeldArm()
    local Weld = Arm:FindFirstChild("Weld")
    if not Weld then
        Weld = Instance.new("Weld", Arm)
        Weld.Part0 = Character.Head
        Weld.Part1 = Arm
    end
    Weld.C0 = Character.Head.CFrame:toObjectSpace(Camera.CoordinateFrame) * CFrame.new(0.9, -1, -1.5) * CFrame.Angles(math.pi/2, 0, 0)
end

while wait() do
    coroutine.resume(coroutine.create(function()
        WeldArm()
    end))
    coroutine.resume(coroutine.create(function()
        WeldCamera()
    end))
end

1 answer

Log in to vote
0
Answered by 9 years ago

This may or may not be the problem. Are you running the script that puts the map into the players camera on a local script? On online mode, the client/server scripts are ran separately. In solo mode, they are ran as one. So the programs might run solo, but that's because there are no difference between client/server. If you make one a local script and one a server script, you will be fine.

0
Yeah, One is a local script the other is a server script, But still does not work in online. xImmortalChaos 565 — 9y
Ad

Answer this question