Im making a system which similar to the game soulshatter,after searching around and messing in my game,this is my current code:
local mouse = game.Players.LocalPlayer:GetMouse()
local runService = game:GetService("RunService")
local uis = game:GetService("UserInputService")
local Target = mouse.Target
local focusing = false
local realtar = nil
uis.InputBegan:Connect(function(input)
if (input.KeyCode == Enum.KeyCode.L) then
focusing = not focusing
if (not focusing) then
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
else
game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
end
end
end)
while game:GetService("RunService").RenderStepped:Wait() do
if (focusing) then
if mouse.Target ~= nil then
local model = mouse.Target.Parent
if model:FindFirstChildOfClass ("Humanoid") then
print "Pointing at a model with Humanoid"
for i,v in pairs(game.Workspace:GetDescendants()) do
if v.Name == Target.Parent:FindFirstChild("HumanoidRootPart").Name then
realtar = v.Parent.HumanoidRootPart
end
end
end
elseif mouse.Target.Parent:FindFirstChildOfClass("Humanoid") then
for i,v in pairs(game.Workspace:GetDescendants()) do
if v.Name == Target.Parent:FindFirstChild("HumanoidRootPart").Name then
realtar = v.Parent.HumanoidRootPart
end
end
end
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(game.Players.LocalPlayer.Character.HumanoidRootPart.Position,Vector3.new(realtar.Position.X,game.Players.LocalPlayer.Character.HumanoidRootPart.Position.Y,realtar.Position.Z))
game.Workspace.CurrentCamera.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame*CFrame.new(Vector3.new(7.5,2.5,10))
end
end
first it work fine if i only use the locking codes,not mouse check(in this case the target is a part),after adding some codes to check players or dummies,there is an error in output
Players.lamgogo.PlayerScripts.PlayerLockSystem:26: attempt to index nil with 'Parent'
im looking for any fixing answear or a new and better locking player code,any help will be much appreciate

2 comments
first,at thefirst lines i wrote "local Target = ...",second,can u give me more explaination or a code sample?i dont know wdym of storing mouse target
oh so i get what u say of store the muse targeti actually use the spawn function so it will save the target,ty for helping