I am trying to make the player’s camera teleport towards the yellow part you can see in the video below, but it is not working and is instead just not moving the camera’s CFrame at all, is there any way to fix this?
(didn’t get any errors)
Here’s the code
script.Parent.SetCamera.OnClientEvent:Connect(function(inorout)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if inorout == "In" then
game.Workspace.CurrentCamera.CFrame = script.Parent.GunAim.CFrame
else
game.Workspace.CurrentCamera.CameraSubject = hum
end
end)
Ok, then try something like this to find out what is causing it?
script.Parent.SetCamera.OnClientEvent:Connect(function(inorout)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
print(inorout)
if inorout == "In" then
print("Viewing GunAim Part")
game.Workspace.CurrentCamera.CFrame = script.Parent.GunAim.CFrame
else
print("Normal Camera")
game.Workspace.CurrentCamera.CameraSubject = hum
end
end)
It looks like the issue might be that you’re using game.Workspace.CurrentCamera instead of player.Camera . In Roblox, every player has their own camera object, so you need to use player.Camera to reference the camera associated with the local player.
It looks like the Camera property of the Player object has been removed in a recent update of Roblox. Instead, you can use the Workspace.CurrentCamera object, which is the camera that is currently being rendered to the player’s screen.
In that case, it might be that the SetCamera event is not being fired, or that the argument passed to the event handler is not equal to "In" . You can add a print statement to the event handler to see what the value of inorout is when the event is fired:
script.Parent.SetCamera.OnClientEvent:Connect(function(inorout)
print(inorout)
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
if inorout == "In" then
game.Workspace.CurrentCamera.CFrame = script.Parent.GunAim.CFrame
else
game.Workspace.CurrentCamera.CameraSubject = hum
end
end)
This will print the value of inorout to the output window, which can help you determine if the event is being fired and what the argument is.