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

[Solved] How to lock a player's camera to head when in seat?

Asked by 3 years ago
Edited 3 years ago

So. Basically what I am trying to do is, when the player is in a seat they cannot move their camera but the camera only looks towards where the head is facing. I made a script and it did not work, then I tried searching it up and some still did not work,,,, anything I am doing wrong? I tried using Enum.CameraType.Follow since the wiki said that the camera moves with the subject but it will not work

game.ReplicatedStorage.LaunchEvent.OnServerEvent:Connect(function(p)
    local pGui = p.PlayerGui
    local button = pGui.Launch.LaunchButton
    local char = p.Character or p.CharacterAdded:Wait()
    local cart = game.ReplicatedStorage.Cart:Clone()
    cart.Name = p.Name.."'s Cart"
    cart.Parent = workspace
    local seat = cart:WaitForChild("Seat")
    seat:Sit(char.Humanoid)
    for i = 3,1,-1 do
        button.Text = i
        wait(1)
    end
    button.Visible = false
    cart.Anchored = false
    seat.Anchored = false
    workspace.Camera.CameraType = Enum.CameraType.Scriptable -- supposed to lock but doesnt ?
    p.CameraMode = Enum.CameraMode.LockFirstPerson
    char.Humanoid.JumpHeight = 0
end)

...help??

0
Btw, nothing comes up in output Omq_ItzJasmin 666 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

Oh nevermind I fixed it. I had to access Current Camera from a local script, then change the CameraType to Scriptable from there. Then I used RenderStepped to constantly change the camera's CFrame to the players head

Script (in serverscriptservice)

game.ReplicatedStorage.LaunchEvent.OnServerEvent:Connect(function(p)
    local pGui = p.PlayerGui
    local button = pGui.Launch.LaunchButton
    local char = p.Character or p.CharacterAdded:Wait()
    local cart = game.ReplicatedStorage.Cart:Clone()
    cart.Name = p.Name.."'s Cart"
    cart.Parent = workspace
    local seat = cart:WaitForChild("Seat")
    seat:Sit(char.Humanoid)
    for i = 3,1,-1 do
        button.Text = i
        wait(1)
    end
    button.Visible = false
    cart.Anchored = false
    seat.Anchored = false
    game.ReplicatedStorage.LaunchEvent:FireClient(p)
    p.CameraMode = Enum.CameraMode.LockFirstPerson
    char.Humanoid.JumpHeight = 0
end)

Local script (in replicated first)

game.ReplicatedStorage.LaunchEvent.OnClientEvent:Connect(function()
    local camera = workspace.CurrentCamera -- now i can change it
    camera.CameraType = Enum.CameraType.Scriptable
    game["Run Service"].RenderStepped:Connect(function()
        camera.CFrame = game.Players.LocalPlayer.Character.Head.CFrame
    end)
end)
Ad
Log in to vote
0
Answered by 3 years ago

The code given below will help

local Player = game:GetService('Players').LocalPlayer

game.ReplicatedStorage.LaunchEvent.OnServerEvent:Connect(function(p)
    local pGui = p.PlayerGui
    local button = pGui.Launch.LaunchButton
    local char = p.Character or p.CharacterAdded:Wait()
    local cart = game.ReplicatedStorage.Cart:Clone()
    cart.Name = p.Name.."'s Cart"
    cart.Parent = workspace
    local seat = cart:WaitForChild("Seat")
    seat:Sit(char.Humanoid)
    for i = 3,1,-1 do
        button.Text = i
        wait(1)
    end
    button.Visible = false
    cart.Anchored = false
    seat.Anchored = false
    Player.CameraMode = Enum.CameraMode.LockFirstPerson -- Locks
    p.CameraMode = Enum.CameraMode.LockFirstPerson
    char.Humanoid.JumpHeight = 0
end)

--To unlock the camera, the following line will work:
Player.LocalPlayer.CameraMode = Enum.CameraMode.Classic -- Unlocks
0
Oh sorry didn't know you already answered... ;( Shounak123 461 — 3y

Answer this question