I wanted to mess with the player’s camera to get the hang of how to use and script the camera. I have this inside of StarterPlayerScripts (localscript)
local cam = workspace.CurrentCamera
repeat
cam.CameraType=Enum.CameraType.Scriptable
until
cam.CameraType==Enum.CameraType.Scriptable
while wait(0.5) do
cam.CFrame = workspace.EEme.CFrame
end
This makes the camera face where the part (“EEme”) is facing, yet it doesn’t teleport to it’s position.
local cam = workspace.CurrentCamera
local Part = workspace:WaitForChild("EEme")
print("This should work")
repeat
cam.CameraType=Enum.CameraType.Scriptable
until cam.CameraType==Enum.CameraType.Scriptable
while wait(0.5) do
print("Should set the Camera's CFrame properly")
cam.CFrame = Part.CFrame
end
local cam = workspace.CurrentCamera
local EEme = workspace:WaitForChild("EEme")
repeat
task.wait()
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
while task.wait(0.5) do
cam.CFrame = EEme.CFrame
end
Instead of cam.CFrame = workspace.EEme.CFrame
I replaced it with cam.CFrame = workspace:WaitForChild("EEme").CFrame
This still does the same thing, I don’t believe it’s because the part hasn’t loaded due to the fact that the camera’s rotation is changed.
The while loop works fine, when I move my camera it teleports back every 0.5 esconds
Is your wait(0.5) call meant to simulate the camera constantly moving during the game running? If so, use RenderStepped to update the position every frame.
To create a CFrame Positioned at Position1 and Looking at Position2:
local cam = workspace.CurrentCamera
local EEme = workspace:WaitForChild("EEme")
local ts = game:GetService("TweenService")
repeat
task.wait()
cam.CameraType = Enum.CameraType.Scriptable
until cam.CameraType == Enum.CameraType.Scriptable
while task.wait() do
ts:Create(cam, TweenInfo.new(0.1), {["CFrame"] = EEme.CFrame})
ts:Play()
end
local Camera = workspace.CurrentCamera
local CameraDestination = game.Workspace:FindFirstChild("EEme")
Camera.CameraType=Enum.CameraType.Scriptable
task.wait(0.1)
Camera.CFrame = CameraDestination.CFrame
Since you stated the while loop, the system knows you want it to be at that CFrame every 0.5 seconds, which is why it teleports back every 0.5 seconds.
The issue you are running into is that the server is overriding your CameraType change. When the player is first spawned, the game likes to automatically set the CameraType back to custom.
Here’s my way of working with the camera. Usually I implement this inside a module called CameraService, but my example will be within your script you provided.
-- local script placed within StarterPlayerScripts
local cam = workspace.CurrentCamera
-- your specified camera type
local cameraType = Enum.CameraType.Scriptable
-- getting the signal that fires when the CameraType property changes
local camTypeChanged = cam:GetPropertyChangedSignal("CameraType")
-- setting initial camera type
cam.CameraType = cameraType
-- funtion that runs when camera type changes
camTypeChanged:Connect(function(newType)
-- if camera type is not the specified value, then reset it back
if newType ~= cameraType then
cam.CameraType = cameraType
end
end)
-- function you can use to change the camera's type
function setCameraType(newCameraType)
cameraType = newCameraType
cam.CameraType = newCameraType
end
-- the rest of your code unchanged
while wait(0.5) do
cam.CFrame = workspace.EEme.CFrame
end
This ensures that the server will not override your camera type changes. However, if you ever want to change the CameraType, you need to call the function within this script (setCameraType)
That’s why I normally put my camera manipulating code within a module script so any script can access the code.
Correct me if I’m wrong, but ModuleScripts need to return a value; You might want to return the CameraType, instead of printing it. Also, if multiple people are using the script, it could spam the output.