How can I update the camera position? I have a button that moves a part with the camera attached to it. When the button is pressed the part moves but the camera stays in the original position. I tried to add something to fix it but it didn’t fix it.
local button = script.Parent
local pov = game.Workspace.CameraSystem.RailClose.Lensa
local camera = game.Workspace.Camera
local cam = true
local model = workspace.CameraSystem.RailClose
local counter = 0
local move = 1
script.Parent.MouseButton1Click:Connect(function()
counter += 1
model:PivotTo(model:GetPivot() + Vector3.new(0, move, 0))
if counter < 10 then return end
counter = 0
move *= -1
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
wait(0.5)
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = pov.CFrame
end)
if I understood you correct, you want your camera to always follow a part
local Camera = Workspace.CurrentCamera
local Part = game.Workspace.CameraSystem.RailClose.Lensa
function UpdateCamera()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Part.CFrame
end
game:GetService("RunService").RenderStepped:Connect(UpdateCamera)
Yeah you understand me right, I tested this script out and it worked, but I have a little problem with it. I have an exit button on my camera but when clicked it doesn’t reset the camera to the player anymore.
i didnt know you have a button to disable it, you will need to change the code to this
local Camera = Workspace.CurrentCamera
local Part = game.Workspace.CameraSystem.RailClose.Lensa
local Button = --Wherever your button is
function UpdateCamera()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Part.CFrame
end
repeat UpdateCamera() until Button.MouseButton1Click
local button = script.Parent
local pov = game.Workspace.CameraSystem.RailClose.Lensa
local camera = game.Workspace.Camera
local cam = true
local Camera = workspace.CurrentCamera
local Part = game.Workspace.CameraSystem.RailClose.Lensa
local model = workspace.CameraSystem.RailClose
local counter = 0
local move = 1
local Button = script.Parent.Parent.ScrollingFrame.cross
script.Parent.MouseButton1Click:Connect(function()
counter += 1
model:PivotTo(model:GetPivot() + Vector3.new(0, move, 0))
if counter < 10 then return end
counter = 0
move *= -1
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Part.CFrame
end)
function UpdateCamera()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Part.CFrame
end
repeat UpdateCamera() until Button.MouseButton1Click
I always forget to add a delay lol Change repeat UpdateCamera() until Button.MouseButton1Click
to repeat UpdateCamera() wait(.1) until Button.MouseButton1Click
local button = script.Parent
local pov = game.Workspace.CameraSystem.RailClose.Lensa
local camera = game.Workspace.Camera
local cam = true
local Camera = workspace.CurrentCamera
local Part = game.Workspace.CameraSystem.RailClose.Lensa
local model = workspace.CameraSystem.RailClose
local counter = 0
local move = 1
local Button = script.Parent.Parent.ScrollingFrame.cross
local run = game:GetService('RunService')
local function UpdateCamera()
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = Part.CFrame
end
script.Parent.MouseButton1Click:Connect(function()
counter += 1
model:PivotTo(model:GetPivot() + Vector3.new(0, move, 0))
if counter < 10 then return end
counter = 0
move *= -1
run.RenderStepped:Connect(UpdateCamera):Disconnect(Button.MouseButton1Click:Wait())
end)