So I’m modifying a first person arms script and I have been stuck on the error (attempt to index nil with ‘CameraOffset’) at line 48. The localscript is in StarterGui. Whats the issue?
Code:
local player=game.Players.LocalPlayer
local camera=workspace.CurrentCamera
local char=player.Character
local humanoid=char:FindFirstChild("Humanoid")
local rep = game:GetService("ReplicatedStorage")
local anim_arms
print(1)
function FirstPerson()
if (camera.focus.p - camera.CoordinateFrame.p).magnitude > 1 then
return false
else
return true
end
end
anim_arms=Instance.new("Model")
anim_arms.Name="Arms_Model"
if player.Character:FindFirstChild("Shirt") then
player.Character:FindFirstChild("Shirt"):clone().Parent=anim_arms
Instance.new("Humanoid",anim_arms)
end
local r,l = rep:WaitForChild("etc"):WaitForChild("a1"):Clone(), rep:WaitForChild("etc"):WaitForChild("a2"):Clone()
r.Material=Enum.Material.SmoothPlastic
r.BrickColor=BrickColor.new("Neon orange")
l.Material=Enum.Material.SmoothPlastic
r.BrickColor=BrickColor.new("Neon orange")
local rw,lw = Instance.new("Weld"),Instance.new("Weld")
-- if rw and SETTINGS.FIRST_PERSON.right_arm then
rw.Part0=r
rw.Part1=char:FindFirstChild("Right Arm")
rw.Parent=r
r.Parent=anim_arms
-- end
-- if lw and SETTINGS.FIRST_PERSON.left_arm then
lw.Part0=l
lw.Part1=char:FindFirstChild("Left Arm")
lw.Parent=l
l.Parent=anim_arms
-- end
l.CanCollide=false
r.CanCollide=false
-- if SETTINGS.FIRST_PERSON.right_arm then
if r:FindFirstChild("RightGrip")~=nil then r:FindFirstChild("RightGrip"):Destroy() end
while wait() do
if FirstPerson() then
if anim_arms ~= nil then
anim_arms.Parent=camera
humanoid.CameraOffset = Vector3.new(0, -0.2, -0.5)
end
else
if anim_arms ~= nil then
anim_arms.Parent=nil
humanoid.CameraOffset = Vector3.new(0,0,0)
end
end
wait()
end
--end
--function End()
-- anim_arms:Destroy()
-- anim_arms=nil
-- humanoid.CameraOffset = Vector3.new(0,0,0)
--end
1 local player=game.Players.LocalPlayer
2 local camera=workspace.CurrentCamera
3 local char=player.Character
4 local humanoid=char:FindFirstChild("Humanoid")
5 local rep = game:GetService("ReplicatedStorage")
6 local anim_arms
7 print(1)
8 function FirstPerson()
9 if (camera.focus.p - camera.CoordinateFrame.p).magnitude > 1 then
10 return false
11 else
12 return true
13 end
14 end
15
16 anim_arms=Instance.new("Model")
17 anim_arms.Name="Arms_Model"
18 if player.Character:FindFirstChild("Shirt") then
19 player.Character:FindFirstChild("Shirt"):clone().Parent=anim_arms
20 Instance.new("Humanoid",anim_arms)
21 end
22 local r,l = rep:WaitForChild("etc"):WaitForChild("a1"):Clone(), rep:WaitForChild("etc"):WaitForChild("a2"):Clone()
23 r.Material=Enum.Material.SmoothPlastic
24 r.BrickColor=BrickColor.new("Neon orange")
25 l.Material=Enum.Material.SmoothPlastic
26 r.BrickColor=BrickColor.new("Neon orange")
27 local rw,lw = Instance.new("Weld"),Instance.new("Weld")
28 -- if rw and SETTINGS.FIRST_PERSON.right_arm then
29 rw.Part0=r
30 rw.Part1=char:FindFirstChild("Right Arm")
31 rw.Parent=r
32 r.Parent=anim_arms
33 -- end
34 -- if lw and SETTINGS.FIRST_PERSON.left_arm then
35 lw.Part0=l
36 lw.Part1=char:FindFirstChild("Left Arm")
37 lw.Parent=l
38 l.Parent=anim_arms
39 -- end
40 l.CanCollide=false
41 r.CanCollide=false
42 -- if SETTINGS.FIRST_PERSON.right_arm then
43 if r:FindFirstChild("RightGrip")~=nil then r:FindFirstChild("RightGrip"):Destroy() end
44 while wait() do
45 if FirstPerson() then
46 if anim_arms ~= nil then
47 anim_arms.Parent=camera
48 humanoid.CameraOffset = Vector3.new(0, -0.2, -0.5)
49 end
50 else
51 if anim_arms ~= nil then
52 anim_arms.Parent=nil
53 humanoid.CameraOffset = Vector3.new(0,0,0)
54 end
55 end
56 wait()
57 end
58 --end
59 --function End()
60 -- anim_arms:Destroy()
61 -- anim_arms=nil
62 -- humanoid.CameraOffset = Vector3.new(0,0,0)
63 --end