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 = Instance.new("Camera") container.Name = "LocalBin" container.Parent = Workspace end -- '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 = Instance.new("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 v:Destroy() end end ghostClone.Parent = container weldBrick.Parent = container weld = Instance.new("Weld", container) weld.Part0 = ghostClone.Middle weld.Part1 = weldBrick weld.C0 = CFrame.new(5, 0, 5) end game:GetService("RunService").RenderStepped:connect(update)
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 * CFrame.new(5, 0, 5):inverse()
should do.