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

Camera is not changing?

Asked by 10 years ago

In my game at the beginning the player's camera is supposed to go to a nice model background and a gui opens up and when the player presses the close button it will close the gui and the camera gets set back to custom. The gui works fine, but the camera does not change to scriptable, here is the code:

player = script.Parent.Parent
c = game.Workspace.Camera

local open = true
local buttonPressed =  false

local button = script.Parent.Parent.StarterGui.ScreenGui.Frame.closeScreen

function changeButtonPressed ()

    buttonPressed = true

end

button.MouseButton1Click:connect(changeButtonPressed)
while open == true do


if buttonPressed == false then
    c.CameraType = "Scriptable"
    pos = Vector3.new(-832.984, 12.576, -680.927)
    targ = Vector3.new(-562.654, 1.741, -789.89)
    c.CoordinateFrame = CFrame.new(pos,targ)
    wait(1)
end
 if buttonPressed == true then
    c.CameraType = "Custom"
    open = false
    end
end

1 answer

Log in to vote
0
Answered by 10 years ago

Try this, this should work fine. (Make sure this is in a local script.)

local player = game.Players.LocalPlayer --Gets the current player.
repeat wait() until player.Character --Wait until the player's character exists.
local c = game.Workspace.CurrentCamera --Gets the player's current camera.

local open = true
local buttonPressed =  false

local button = player:WaitForChild("PlayerGui").ScreenGui.Frame.closeScreen

button.MouseButton1Click:connect(function() --Anonymous functions allow for less lines of code.
    buttonPressed = true
end)

while open == true do
    if buttonPressed == false then --Don't make separate if statements for each comparison, use else and elseif to your advantage.
        c.CameraType = "Scriptable"
        pos = Vector3.new(-832.984, 12.576, -680.927)
        targ = Vector3.new(-562.654, 1.741, -789.89)
        c.CoordinateFrame = CFrame.new(pos) --This is where the camera is positioned.
        c.Focus = CFrame.new(targ) --This is where the camera is focused at.
        wait(1)
    else
        c.CameraType = "Custom"
        c.CameraSubject = player.Character:WaitForChild("Humanoid") --Just in case the camera doesn't return back to normal.
        open = false
    end
end
0
thank you it is working fine now! CaptainRuno 40 — 10y
Ad

Answer this question