Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago

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.

Ad

Answer this question