2.5D camera Manipulation Bug

I found a bug in my 2D Camera Manipulation script, the local script runs in StarterPlayerScripts and must be named ‘CameraScript’ when I run the script in the Roblox client the script doesn’t work but in Roblox studio, the script works just fine. I don’t know what causes this and if anyone can troubleshoot it please help. Here is the local script:

local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera

player.CharacterAdded:Wait()
player.Character:WaitForChild(“HumanoidRootPart”)

camera.CameraSubject = player.Character.HumanoidRootPart
camera.CameraType = Enum.CameraType.Attach
camera.FieldOfView = 30

game:GetService(‘RunService’).Stepped:Connect(function()
camera.CFrame = CFrame.new(player.Character.HumanoidRootPart.Position) * CFrame.new(0,0,30)
end)

1 Like

See if this helps you out, This is a local script in starterCharacterScripts, It’s a pretty simple

local camera = game.Workspace.CurrentCamera --we need to get the camera
local player = game:GetService("Players").LocalPlayer --Next the player
local character = player.Character or player.Character:Added() --Make sure we got the character
--Next we will create a function and name it cameraUpdate
function cameraUpdate() -- we get the torso
    local torso = character:WaitForChild("Torso") --Here is the player's torso
    --Now we can set the camera coordinateframe to all torso cframes
    camera.CoordinateFrame = CFrame.new(torso.CFrame.X + 0 --[[This is the X position change this to what you want.]],torso.CFrame.Y + 2.4 --[[Change 2.4 which is the y value to whatever you like]] ,12 --[[This is the Z value or the distance change it to whatever you like]])
end

game:GetService("RunService").RenderStepped:connect(cameraUpdate) --connects the runservice to the function

All the script does is change the Camera coordinate frame to be facing the torso side.

Thank you for your recommendation. However, I found a bug on line 8 camera.CoordinateFrame = CFrame.new(torso.CFrame.X + nil,torso.CFrame.Y + 2.4,12)
end

Oh, sorry put the script in StarterGui, my bad

the script doesnt work. is something to do with the name?

Are you using r15??
(30 CHARS)

1 Like

yes
[30 chars bruh!]
[30 chars bruh!]

if your using r15, put this in a local script, in starterGui

local camera = game.Workspace.CurrentCamera 
local player = game:GetService("Players").LocalPlayer 
local character = player.Character or player.Character:Added()

function cameraUpdate() 
    local torso = character:WaitForChild("HumanoidRootPart")  -- There is no torso for r15
   
    camera.CoordinateFrame = CFrame.new(torso.CFrame.X + 0,torso.CFrame.Y + 2.4 ,12 )
end

game:GetService("RunService").RenderStepped:connect(cameraUpdate) 
2 Likes

Finally works, thanks for your efforts.