Camera movement issue

I made a dining table where you can hide under it.

I made this script that move the camera of the player under the table:

wait(0.1)
local TweenService = game:GetService("TweenService")
local TweenInfo = TweenInfo.new(1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut, 0, false, 0)

local Camera = workspace.CurrentCamera
local HideCameraPos = workspace.House.Floor1.DiningRoom.DiningTable.Table.HideCameraPos
local PlayerPos = HideCameraPos.Parent.PlayerPos
local CamPos = HideCameraPos.Parent.CamPos

local Prompt = HideCameraPos.Attachment.HidePrompt

local Hidden = false

Prompt.Triggered:Connect(function(player)
	if Hidden == false then --Hide the player
		local HideTween = TweenService:Create(Camera, TweenInfo, {CFrame = HideCameraPos.CFrame})
		
		PlayerPos.CFrame = player.Character:FindFirstChild("Head").CFrame
		CamPos.CFrame = Camera.CFrame
		Camera.CameraType = Enum.CameraType.Scriptable
		
		HideTween:Play()
		wait(1)
		
		Prompt.Enabled = true
		Prompt.ActionText = "Get out"
		
		Hidden = true
		
	elseif Hidden == true then --Unhide the player
		local GetOutTween = TweenService:Create(Camera,TweenInfo, {CFrame = CamPos.CFrame})
		
		GetOutTween:Play()
		
		Prompt.ActionText = "Hide"
		wait(1)
		
		Camera.CameraType = Enum.CameraType.Custom
		PlayerPos.CFrame = HideCameraPos.CFrame
		CamPos.CFrame = HideCameraPos.CFrame
		
		Hidden = false
	end
end)

My problem is in this part:

if Hidden == false then --Hide the player
		local HideTween = TweenService:Create(Camera, TweenInfo, {CFrame = HideCameraPos.CFrame})
		
		PlayerPos.CFrame = player.Character:FindFirstChild("Head").CFrame
		CamPos.CFrame = Camera.CFrame
		Camera.CameraType = Enum.CameraType.Scriptable
		
		HideTween:Play()
		wait(1)
		
		Prompt.Enabled = true
		Prompt.ActionText = "Get out"
		
		Hidden = true
		

I want the player to be able to look around while being under the table, wich this script does not allow it to. I tried changing the CameraType without success. Keep in note that another script anchor and move the player under the table when hidden, so that every player see that player under the table. Here is the script:

local Prompt = script.Parent

local Debounce = false

local HidePlayerPos = Prompt.Parent.Parent.Parent.HidePlayerPos
local PlayerOriginalPos = Prompt.Parent.Parent.Parent.PlayerOriginalPos

Prompt.Triggered:Connect(function(player)
	local HumanoidRootPart = player.Character:FindFirstChild("HumanoidRootPart")
	
	if Debounce == false then
		
		Prompt.Enabled = false
		
		Debounce = true
		
		PlayerOriginalPos.CFrame = HumanoidRootPart.CFrame
		
		HumanoidRootPart.CFrame = HidePlayerPos.CFrame
		HumanoidRootPart.Anchored = true
		
	elseif Debounce == true then
		
		Prompt.Enabled = true
		
		Debounce = false
		
		HumanoidRootPart.CFrame = PlayerOriginalPos.CFrame
		HumanoidRootPart.Anchored = false
		
		PlayerOriginalPos.CFrame = HidePlayerPos.CFrame
	end
end)
1 Like

Try using the Fixed camera type. I believe this lets the player move their camera in 360 but still keeps the camera in the spot determined by the CFrame, (I think you do need Camera.CameraSubject set to nil though, otherwise it goes on the character).

Edit:

What happened when you tried to change the camera? Did it get positioned wrong, cause no change, get stuck, etc?

Maybe try replacing this line:

Camera.CameraType = Enum.CameraType.Scriptable

with

Camera.CameraType = Enum.CameraType.Fixed

and see if that does what you’re looking for.

1 Like

I tried changing the CameraType to Classic but the character glitches around and the character move with the camera, wich I don’t want to happend. For the Fixed the camera just lay in a position without being able to move it.

As for the Camera.CameraSubject I set it to the player head and it works, so thank you !

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.