Hi (again)! I am trying to make a part follow where my camera is (if you don't know yet). It doesn't go anywhere near the camera and goes in one certain spot. Help! (there is no error)
local owner = game.Players.iiDkOffical local head = Instance.new("Part") head.Name = "Head" head.Anchored = true print("Made Part") local group = Instance.new("Model") group.Name = "Unknown" group.Parent = game:GetService("Workspace") head.Parent = group local humanoid = Instance.new("Humanoid") humanoid.Parent = group print("Made group") head.Size = Vector3.new(1,1,1) while true do wait(0.25) group.Name = owner.Name.." - Camera" head.CFrame = game:GetService("Workspace").Camera.CFrame end
CurrentCamera is the actual Camera that is adjusted on the Player's screen, referencing 'Camera' will be setting the CFrame to a static position. Since the Camera is also rendered every Frame, we can tell the Part to match it's position at the same rate with RunService's
.Heartbeat signal. This way we can make it follow the Camera smoothly.
local RunService = game:GetService("RunService") RunService.Heartbeat:Connect(function() head.CFrame = workspace.CurrentCamera.CFrame end)
Just made the script a bit neater, this should work
--- put this in a localscript under StartPlayerScripts which is under StarterPlayer local camera = workspace.CurrentCamera local part wait(3) -- just to make sure everything loaded game["Run Service"].Heartbeat:Connect(function() if not part then local player = game.Players.LocalPlayer local char = player.Character part = Instance.new("Part") part.Name = "CAMERAPART" part.Anchored = true part.Parent = char part.CFrame = camera.CFrame end part.CFrame = camera.CFrame end)
Hope I helped, if you have any questions please let me know