Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I move/set the Camera to a certain player?

The code that I rewritten many times was pretty shit so I was wondering if I could get some help? The script is supposed to pan to the Player if he enters your house.

if (game.Workspace.House.Position - game.Players:GetPlayers().Position).magnitude < 15 then
	
	
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
game.Workspace.CurrentCamera.CFrame = game.Workspace.CurrentCamera.CFrame:Lerp(game.Players:GetPlayers().CFrame)
	
else
	
	game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
	
end

2 comments

0

I'm assuming this is in a server script. You can only change the camera in a local script

0

You can use that same script, but instead of checking using game.Players:GetPlayers() just check for the LocalPlayer, and if their HumanoidRootPart is within distance of the house

1 answer

I had to figured it out myself, thanks a lot guys.

wait(2)


local RunService = game:GetService("RunService")


RunService.RenderStepped:Connect(function()
	local magnitude = (game.Players.LocalPlayer.Character:FindFirstChild("Head").Position - workspace:FindFirstChild("Part").Position).Magnitude
	if magnitude < 15 then	
		workspace.CurrentCamera.CameraSubject=game.Workspace:FindFirstChild("Part")
	   else
			print(magnitude)
			workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")	
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.