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

How would I go about making the camera go back to the player when my PlayButton is clicked?

Asked by 3 years ago

Hello!

I have a script that turns you into an animal when you press a text button. However, for some reason when you press the text button it doesn't return the camera to the player. I have messed with the camera a bit, (when I say I messed with it, I mean I scripted some things for my main menu that had to do with the camera.) but everything seems to be working fine. I have the script that I think you guys can help me fix. If you can help, please do!

----< Variables

local Player = script.Parent.Parent.Parent
local Content = script.Parent.Main.ScrollingFrame.FrameHolder
local Animals = game.ReplicatedStorage.Animals
local SetAnimal = Animals.Parent.AS_Remotes.SetAnimal
local Camera = game.Workspace.CurrentCamera

----< Functions

for index,item in pairs(Animals:GetChildren()) do
    if item:FindFirstChild("Humanoid") then
        local ViewportFrame = Instance.new("ViewportFrame")
        ViewportFrame.Parent = Content
        ViewportFrame.BackgroundTransparency = 1

        local Button = Instance.new("TextButton")
        Button.Parent = ViewportFrame
        Button.Position = UDim2.new(0,0,1,0)
        Button.Size = UDim2.new(1,0,0,15)
        Button.BorderSizePixel = 0
        Button.BackgroundColor3 = Color3.fromRGB(102, 102, 102) -- Change the background colour of the Select button under the image of the custom model.
        Button.BackgroundTransparency = 0.4 -- Change the background transparency of the select button under the image of the custom model.
        Button.Text = "Select"
        Button.TextColor3 = Color3.fromRGB(255, 255, 255) -- Change the text colour of the Select button under the image of the custom model.
        Button.TextScaled = true

        local Preview = item:Clone()
        Preview.Parent = ViewportFrame
        local Camera = Instance.new("Camera")
        Camera.Parent = ViewportFrame
        Camera.CFrame = Preview.Head.CFrame + Preview.Head.CFrame.LookVector * 12  -- The Custom Model Image. Increase to zoom out. Decrease to zoom in. 
        Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)


        ViewportFrame.CurrentCamera = Camera

        Button.MouseButton1Down:Connect(function()
            local val = Instance.new("BoolValue")
            val.Name = "AnimalValue"
            val.Parent = Player
            Player.CameraMaxZoomDistance = 128
            Player.CameraMinZoomDistance = 40
            script.Parent.Enabled = false
            local ChosenAnimal = item:Clone()
            local CurrentCharacter = Player.Character
            local LocalScripts = {}

            for index2,item2 in pairs(game.StarterPlayer.StarterCharacterScripts:GetChildren()) do
                if item2:IsA('LocalScript') then
                    table.insert(LocalScripts,item2:Clone())
                else
                    item2:Clone().Parent = ChosenAnimal
                end
            end

            CurrentCharacter.Health:Clone().Parent = ChosenAnimal
            table.insert(LocalScripts,CurrentCharacter.Animate:Clone())     
            ChosenAnimal.Parent = workspace
            Player.Character = ChosenAnimal
            for index2,item2 in pairs(LocalScripts) do
                item2.Parent = ChosenAnimal
            end 
            ChosenAnimal.Humanoid.Parent.HumanoidRootPart.CFrame = workspace.SpawnLocations.TP_Game.CFrame
            SetAnimal:FireClient(Player,ChosenAnimal.Humanoid)

            local Connection

            local function onDied()
                wait(game.Players.RespawnTime)
                Player:LoadCharacter()
                script.Parent.Enabled = true
                if Connection then
                    Connection:Disconnect()
                end
            end

            Connection = ChosenAnimal.Humanoid.Died:Connect(onDied)
        end)
    end
end
0
You need to return the camera back to the main camera. I.e when you make a new camera and change the current camera, you need to change it back to the old camera later on. Calagoz 0 — 3y
0
How would I go about doing that? Shadow_12306 7 — 3y

Answer this question