local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent
local function moveCamera(player)
local originalCamera = player.Camera
player.Camera = camPenicillin
print("Camera moved to")
wait(10)
player.Camera = originalCamera
print("Camera returned")
end
proximityPrompt.TriggerEnded:Connect(function()
local player = Players.LocalPlayer
if player then
moveCamera(player)
else
print("LocalPlayer not found")
end
end)
First create a serverscript into the proximity prompt:
local Proxy = script.Parent
local Event = --Any event location
Proxy.Triggered:Connect(function(playerwhotriggered)
print('I got triggered')
Event:FireClient(playerwhotriggered)
end)
Client
local Event =nil --Any event location
local player = game.Players.LocalPlayer
local Player_Camera = workspace.CurrentCamera
local part_camera = nil -- The part that you want as camera
local rs = game:GetService("RunService")
Event.OnClientEvent:Connect(function()
Player_Camera.CameraType = Enum.CameraType.Custom
rs.RenderStepped:Connect(function()
Player_Camera.CFrame = part_camera.CFrame
end)
end)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local CamPos = ReplicatedStorage:WaitForChild("Cam"):WaitForChild("CamSpore")
local Event = CamPos
local CamSpore = Workspace:WaitForChild("Spore room")
local player = Players.LocalPlayer
local Player_Camera = Workspace.CurrentCamera
local part_camera = CamSpore:WaitForChild("Camera")
local rs = game:GetService("RunService")
local function returnCameraToPlayer()
local originalCFrame = Player_Camera.CFrame
rs.RenderStepped:Connect(function()
Player_Camera.CFrame = part_camera.CFrame
end)
wait(2)
Player_Camera.CFrame = originalCFrame
end
Event.OnClientEvent:Connect(returnCameraToPlayer)
There is one problem. When I want to return the camera to the player, nothing happens. No errors in output
local Players = game:GetService("Players")
local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent
local function moveCamera(player)
local originalCameraType = workspace.CurrentCamera.CameraType
local originalCameraCFrame = workspace.CurrentCamera.CFrame
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = CFrame.new(camPenicillin.Position)
print("Camera moved to CamPenicillin")
wait(10)
workspace.CurrentCamera.CameraType = originalCameraType
workspace.CurrentCamera.CFrame = originalCameraCFrame
print("Camera returned to original position")
end
proximityPrompt.TriggerEnded:Connect(function()
local player = Players.LocalPlayer
if player then
moveCamera(player)
else
print("LocalPlayer not found")
end
end)
local Camera = game.Workspace.CurrentCamera
local Part2 = game.Workspace:FindFirstChild("Part2")
if Part2 then
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = CFrame.new(Part2.Position)
end
``
Use current camera local Camera = workspace.CurrentCamera
Change camera type in function “MoveCamera” Camera.CameraType = Enum.CameraType.Custom
put local script to StarterPlayerScripts
full script :
local Camera = workspace.CurrentCamera
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local camPenicillin = script.Parent.Parent.Parent:WaitForChild("CamPenicillin")
local proximityPrompt = script.Parent
local function moveCamera(player)
Camera.CameraType = Enum.CameraType.Scriptable
Camera.CFrame = camPenicillin.CFrame
print("Camera moved to")
wait(10)
Camera.CFrame = player.Character.HumanoidRootPart.CFrame
Camera.CameraType = Enum.CameraType.Custom
print("Camera returned")
end
proximityPrompt.TriggerEnded:Connect(function()
local player = Players.LocalPlayer
if player then
moveCamera(player)
else
print("LocalPlayer not found")
end
end)
is the direction of the CFrame
you need to set it to the place where the camera is to be pointed