Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

This script should return the players camera back, but it doesn't?

This script makes it so that when you click a button it shows you a different view via campart. When you click the X button it should return your camera, but it doesn't. Maybe I am just missing the right thing?

Script:

local xbutton = game.Players.LocalPlayer:FindFirstChild("PlayerGui").Exitcamera.X
local Players = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

xbutton.MouseButton1Click:Connect(function(player)
	repeat wait() until Players.Character
	
	camera.CameraType = "Scriptable"
	camera.CFrame = workspace.Camera
	
	game.Players.LocalPlayer:FindFirstChild("PlayerGui").Exitcamera.Enabled = false
game.Players.LocalPlayer:FindFirstChild("PlayerGui").Camera.Enabled = true
	
end)

1 answer

✓ Accepted answer

Theres a couple things about the player's camera:

  1. The camera type for the player is Track
  2. you got to set the cframe back to the players head

So you almost got it but getting it back was a problem Heres your script fixed:

local xbutton = game.Players.LocalPlayer:FindFirstChild("PlayerGui").Exitcamera.X
local Players = game.Players.LocalPlayer
local camera = game.Workspace.CurrentCamera

xbutton.MouseButton1Click:Connect(function(player)
    repeat wait() until Players.Character

    camera.CameraType = "Track"
    camera.CFrame = Players.Character.Head.CFrame

    game.Players.LocalPlayer:FindFirstChild("PlayerGui").Exitcamera.Enabled = false
    game.Players.LocalPlayer:FindFirstChild("PlayerGui").Camera.Enabled = true

end)

Also change your Players variable to Player, it kinda gets confusing when you have the Players Service. You can set the camera type back to scriptable and set it back to track to have like a spy-mode or spectate mode. I just learned the camera today lol.

You can ask clarification anytime.

This discussion is preserved as it was. New answers, comments, and votes are closed.