Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i make a camera that follows the player?

I am trying to make a camping game on roblox and I am trying to make a gui that shows the player because the camera is following the player and this is all i got for a camera block

local camera = workspace.CurrentCamera -- which is the camera
local realcamera = workspace.Camerablock -- which is the camera block

repeat wait()
	camera.CameraType = Enum.CameraType.Scriptable
until camera.CameraType == Enum.CameraType.Scriptable
camera.CFrame = realcamera.CFrame

But i need help because i don't know what i do to make it go in front of the player pls help me smart people

1 answer

✓ Accepted answer

THis here will help you but make sure to be in R15 setting or it wont work

and make sure to add a HumanoidRootPart or this also wont work so add it to the script

local camera = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local runService = game:GetService('RunService')

local pre, curr, diff

local function setupCamera()
    wait()
    pre = player.Character:WaitForChild("UpperTorso").Position
    camera.CFrame = CFrame.new(pre+Vector3.new(0, 5, 10), pre)
end

local function onUpdate()
    if pre and player.Character and player.Character:FindFirstChild("UpperTorso") then
        curr = player.Character.UpperTorso.Position
        diff = curr - pre
        pre = curr
        camera.CFrame = camera.CFrame + diff
    end
end

player.CharacterAdded:connect(setupCamera)
runService:BindToRenderStep("Camera",Enum.RenderPriority.Camera.Value,onUpdate)

6 comments

0

THANK YOU

0

Np

0

wait but how do i put it into the gui?

0

you know, you can make it work with R15 and R6 (or any rig type) just by using "HumanoidRootPart" instead of "UpperTorso", and reposition if it's too low.

0

wait but what type of script do i use? because the one i am using is a normal script also why is it not showing in the gui

0

If it's for a GUI or it's client sided, it's a local script, if it's a server sided script it's a normal script

This discussion is preserved as it was. New answers, comments, and votes are closed.