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

How do you make it so when your in first person you can move your mouse when a gui pops up?

Asked by 4 years ago

So when a player join my game they are greeted my a "Character Selection" but the thing is you cant move your mouse because your in first person how do you make it so you can move your mouse in the gui but when you select a character it goes back to first person and you cant move your mouse? The GUI script i have rn

local Player = script.Parent.Parent.Parent
local Content = script.Parent.MainFrame.ScrollingFrame.Content
local Characters = game.ReplicatedStorage.Characters
local SetSubject = Characters.Parent.SetSubject

for index,item in pairs(Characters: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(255,255,255)
        Button.Text = "Spawn"
        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 * 5
        Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)

        ViewportFrame.CurrentCamera = Camera

        Button.MouseButton1Down:Connect(function()
            script.Parent.Enabled = false
            local ChosenCharacter = 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 = ChosenCharacter
                end
            end

            CurrentCharacter.Health:Clone().Parent = ChosenCharacter
            table.insert(LocalScripts,CurrentCharacter.Animate:Clone())    
            ChosenCharacter.Parent = workspace
            Player.Character = ChosenCharacter
            for index2,item2 in pairs(LocalScripts) do
                item2.Parent = ChosenCharacter
            end
            SetSubject:FireClient(Player,ChosenCharacter.Humanoid)

            local Connection

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

            Connection = ChosenCharacter.Humanoid.Died:Connect(onDied)

        end)

    end
end

1 answer

Log in to vote
0
Answered by 4 years ago

It automatically unlocks your mouse when a GUI is active

local Player = script.Parent.Parent.Parent
local Content = script.Parent.MainFrame.ScrollingFrame.Content
local Characters = game.ReplicatedStorage.Characters
local SetSubject = Characters.Parent.SetSubject

for index,item in pairs(Characters: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(255,255,255)
        Button.Text = "Spawn"
        Button.TextScaled = true
    Button.Active = 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 * 5
        Camera.CFrame = CFrame.new(Camera.CFrame.Position,Preview.Head.Position)

        ViewportFrame.CurrentCamera = Camera

        Button.MouseButton1Down:Connect(function()
            script.Parent.Enabled = false
            local ChosenCharacter = 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 = ChosenCharacter
                end
            end

            CurrentCharacter.Health:Clone().Parent = ChosenCharacter
            table.insert(LocalScripts,CurrentCharacter.Animate:Clone())    
            ChosenCharacter.Parent = workspace
            Player.Character = ChosenCharacter
            for index2,item2 in pairs(LocalScripts) do
                item2.Parent = ChosenCharacter
            end
            SetSubject:FireClient(Player,ChosenCharacter.Humanoid)

            local Connection

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

            Connection = ChosenCharacter.Humanoid.Died:Connect(onDied)

        end)

    end
end

0
still does not work. What im think is that the script i made for it to be first person but yeah thanks so much for the help :D DataCordz 6 — 4y
Ad

Answer this question