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

How do i make a camera that follows the player?

Asked by 4 years ago
Edited 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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)

0
THANK YOU DahNOOB_TY 4 — 4y
0
Np DuckyRobIox 280 — 4y
0
wait but how do i put it into the gui? DahNOOB_TY 4 — 4y
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. Mayk728 855 — 4y
View all comments (2 more)
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 DahNOOB_TY 4 — 4y
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 Iroxxigar 24 — 4y
Ad

Answer this question