So I have a lock on camera script.
How can I get the camera back to following the player. I’ve tried setting the Target = nil
but that caused an issue where i couldn’t move the camera at all.
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local Target = nil
local CamBlock = Instance.new("Part", workspace.CurrentCamera)
CamBlock.Size = Vector3.new(1,1,1)
CamBlock.Transparency = 1
CamBlock.CanCollide = false
local BP = Instance.new("BodyPosition", CamBlock)
BP.maxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.D = 500
local BUI = Instance.new("BillboardGui")
BUI.Size = UDim2.new(6,0,6,0)
BUI.AlwaysOnTop = true
local IL = Instance.new("ImageLabel", BUI)
IL.Image = "rbxassetid://4569894478"
IL.BackgroundTransparency = 1
IL.Size = UDim2.new(1,0,1,0)
UIS.InputBegan:connect(function(input,typing)
if typing then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if mouse.Target and mouse.Target.Parent:findFirstChild("Humanoid") and mouse.Target ~= Player.Name then
Target = mouse.Target.Parent
CamBlock.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BP.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BUI.Parent = Target.PrimaryPart
else
workspace.CurrentCamera.CameraType = "Fixed"
end
end
end)
RS.RenderStepped:connect(function()
if Target and (c.HumanoidRootPart.Position-Target.PrimaryPart.Position).magnitude < 80 and Target.Humanoid ~= nil and Target.Humanoid.Health > 0 and c.Humanoid ~= nil and c.Humanoid.Health > 0 then
local CamPos = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BP.Position = CamPos
workspace.CurrentCamera.CameraType = "Scriptable"
workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position,Target.PrimaryPart.Position)
local Dist = (c.HumanoidRootPart.Position-Target.PrimaryPart.Position).magnitude
IL.ImageTransparency = 1-(Dist/80)
else
BUI.Parent = nil
Target = nil
workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position,Target.PrimaryPart.Position)
workspace.CurrentCamera.CameraType = "Scriptable"
end
end)
--I DID NOT MAKE THIS
local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local mouse = Player:GetMouse()
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local Target = nil
local CamBlock = Instance.new("Part", workspace.CurrentCamera)
CamBlock.Size = Vector3.new(1,1,1)
CamBlock.Transparency = 1
CamBlock.CanCollide = false
local BP = Instance.new("BodyPosition", CamBlock)
BP.maxForce = Vector3.new(math.huge,math.huge,math.huge)
BP.D = 500
local BUI = Instance.new("BillboardGui")
BUI.Size = UDim2.new(6,0,6,0)
BUI.AlwaysOnTop = true
local IL = Instance.new("ImageLabel", BUI)
IL.Image = "rbxassetid://4569894478"
IL.BackgroundTransparency = 1
IL.Size = UDim2.new(1,0,1,0)
UIS.InputBegan:connect(function(input,typing)
if typing then return end
if input.UserInputType == Enum.UserInputType.MouseButton1 then
if mouse.Target and mouse.Target.Parent:findFirstChild("Humanoid") and mouse.Target ~= Player.Name then
Target = mouse.Target.Parent
CamBlock.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BP.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BUI.Parent = Target.PrimaryPart
else
Target= nil --THIS IS WHERE I SET IT TO NIL
end
end
end)
RS.RenderStepped:connect(function()
if Target and (c.HumanoidRootPart.Position-Target.PrimaryPart.Position).magnitude < 80 and Target.Humanoid ~= nil and Target.Humanoid.Health > 0 and c.Humanoid ~= nil and c.Humanoid.Health > 0 then
local CamPos = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(0,4,9).p
BP.Position = CamPos
workspace.CurrentCamera.CameraType = "Scriptable"
workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position,Target.PrimaryPart.Position)
local Dist = (c.HumanoidRootPart.Position-Target.PrimaryPart.Position).magnitude
IL.ImageTransparency = 1-(Dist/80)
else
BUI.Parent = nil
Target = nil
workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position,Target.PrimaryPart.Position)
workspace.CurrentCamera.CameraType = "Scriptable"
end
end)