My goal is when the player is sitting, he is looking from a block but it doesn’t work
The local script put it in Server Storage and StarterPlayerScripts, and it doesn’t work.
Create a local script and write this code. It’s done wrong, help me make it work.
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = game.workspace.Camara
char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
if isSeated and seat.Name == "CameraSeat" then
camPart.CameraType = Enum.CameraType.Custom
camPart.CFrame = camPart.CFrame
else
end
end)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = workspace.Camara
char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
if isSeated and seat.Name == "CameraSeat" then
camPart.CameraType = Enum.CameraType.Scriptable
camPart.CFrame = camPart.CFrame
else
camPart.CameraType = Enum.CameraType.Custom
end
end)
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local cam = workspace.CurrentCamera
local camPart = Instance.new("Part") -- Create a new Part object to use as the camera seat
camPart.Name = "CameraSeat"
camPart.Anchored = true
camPart.Size = Vector3.new(1, 1, 1) -- Set the size of the seat
camPart.Parent = workspace -- Parent the seat to the workspace
char:WaitForChild("Humanoid").Seated:Connect(function(isSeated, seat)
if isSeated and seat.Name == "CameraSeat" then
cam.CameraType = Enum.CameraType.Scriptable -- Change the camera type to Scriptable
cam.CFrame = camPart.CFrame -- Set the camera's CFrame to the seat's CFrame
else
cam.CameraType = Enum.CameraType.Custom -- Change the camera type back to Custom when not seated
end
end)
Make sure to put this local script in StarterPlayerScripts, as it needs to run on the client side. Additionally, make sure to add a part named “CameraSeat” in your game to act as the seat for the player.
To set the orientation (rotation) of the camPart, you can use the CFrame.new() function. Here’s an example of how to set the position and orientation of the camPart:
This will set the camPart’s position to Vector3.new(49.604, 16.497, -262.572) and its orientation to Vector3.new(0, 280, 0). Adjust the values accordingly to achieve the desired orientation for your camera seat.
delete the new instance and use a new block to use as the camera, but the script has an error, when the player dies or restarts, the camera does not activate.
how can you solve it.