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??
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)
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