Hello, im making hiding spots for my game and im faced with a problem.
I want it so that when the player hide under the table, the camera get locked in first person and get back to normal when the player get out of the hiding spot. How do I achieve that ?
Here is the script if it help:
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
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
Camera.CameraSubject = script.Parent:FindFirstChild("Head")
HideTween:Play()
wait(1)
Camera.CameraType = Enum.CameraType.Custom
Prompt.Enabled = true
Prompt.ActionText = "Get out"
Hidden = true
elseif Hidden == true then
local GetOutTween = TweenService:Create(Camera,TweenInfo, {CFrame = CamPos.CFrame})
GetOutTween:Play()
Prompt.ActionText = "Hide"
wait(1)
Camera.CameraSubject = script.Parent:FindFirstChildWhichIsA("Humanoid")
Camera.CameraType = Enum.CameraType.Custom
PlayerPos.CFrame = HideCameraPos.CFrame
CamPos.CFrame = HideCameraPos.CFrame
Hidden = false
end
end)