You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? To debug a camera bug on my mobile lock on script
-
What is the issue? Whenever you try to lock onto a yourself and another player/model your camera crashes and teleports into nothingness
-
What solutions have you tried so far? Tried numerous conditions, no bugs in the output, nothing
the script:
local camera = game.Workspace.Camera
local filter = {}
local RS = game:GetService("RunService")
local Target = nil
Enabled = true
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 CAS = game:GetService("ContextActionService")
Player = game.Players.LocalPlayer
c = Player.Character
function CancelTarget()
if Enabled == true then
Target = nil
end
end
local CT = CAS:BindAction("CancelTarget", CancelTarget, true, "M")
CAS:SetPosition("CancelTarget", UDim2.new(0.72, -105, 0.10, -100))
uis.TouchTapInWorld:Connect(function(position, processed)
local ray = camera:ViewportPointToRay(position.X, position.Y, 0)
ray = Ray.new(ray.Origin, ray.Direction * 500)
local target, point, surface = workspace:FindPartOnRayWithIgnoreList(ray, filter)
table.insert(filter, Player.Character)
if not target then return end
if target.Parent:findFirstChildOfClass("Humanoid") then
Target = target.Parent
CamBlock.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(3,3,9).p
BP.Position = CFrame.new(c.HumanoidRootPart.Position, Target.PrimaryPart.Position)*CFrame.new(3,3,9).p
end
RS.RenderStepped:connect(function()
if Target and (c.HumanoidRootPart.Position-Target.PrimaryPart.Position).magnitude < 60 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(3,3,9).p
c.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(c.HumanoidRootPart.Position.X,c.HumanoidRootPart.Position.Y,c.HumanoidRootPart.Position.Z),Vector3.new(Target.HumanoidRootPart.Position.X,c.HumanoidRootPart.Position.Y,Target.HumanoidRootPart.Position.Z))
BP.Position = CamPos
workspace.CurrentCamera.CameraType = "Scriptable"
if Target then
workspace.CurrentCamera.CFrame = CFrame.new(CamBlock.Position,Target.PrimaryPart.Position)
elseif
not Target then
workspace.CurrentCamera.CameraType = "Custom"
target = nil
else
Target = nil
workspace.CurrentCamera.CameraType = "Custom"
end
end
end)
end)