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

Working, but not working?

Asked by 9 years ago

The following code is supposed to generate a 'Ghost' (model) based on the camera's coordinate frame. The ghost model appears in the game, but it doesn't move at all from the original position it was in when I made it.

What happens is a new camera called LocalBin is created (a container for my local parts), the Ghost model is inserted into it, a part called weldBrick is created and placed at the camera's CoordinateFrame (for creating a weld between the camera and ghost), and a weld is created that is supposed to link the ghost and weldBrick.

The hierarchy is as follows:

Workspace>LocalBin>Ghost, weldBrick, Weld

No output errors.

repeat wait() until Workspace.CurrentCamera ~= nil

-- attempt to find a container; create a new one if it doesn't exist
local container = Workspace:FindFirstChild("LocalBin")
if not container then
    container ="Camera")
    container.Name = "LocalBin"
    container.Parent = Workspace

-- 'container' will be used to contain all local parts. Below I copied the code from
-- before to create a local platform.

function update()
    camera = game.Workspace.CurrentCamera

    weldBrick ="Part")
    weldBrick.CFrame = Workspace.CurrentCamera.CoordinateFrame
    weldBrick.Anchored = true
    weldBrick.CanCollide = false
    weldBrick.Transparency = 0.5
    weldBrick.Name = "weldBrick"

    ghost = script.Ghost
    ghostClone = ghost:clone()

    for i, v in pairs(container:GetChildren()) do
        if v.Name == "Ghost" or v.Name == "weldBrick" or v.Name == "Weld" then

    ghostClone.Parent = container
    weldBrick.Parent = container

    weld ="Weld", container)
    weld.Part0 = ghostClone.Middle
    weld.Part1 = weldBrick
    weld.C0 =, 0, 5)


1 answer

Log in to vote
Answered by
jobro13 980 Moderation Voter
9 years ago

Your code is almost correct! However, welds will not work if one or both of the parts are anchored. Unanchor the weldBrick on line 19 and see if that works. As you are using render stepped, my guess is that it works.

However, what would be even better is to just move the Ghost model every frame to the right CFrame. ghostClone.Middle.CFrame = game.Workspace.CurrentCamera.CoordinateFrame *, 0, 5):inverse() should do.


Answer this question