So I’m making a swinging game and it keeps throwing me the error of attempt to index nil with 'Position'. Even though it works perfectly fine before.
This seems to be happening at random times and I don’t know how to fix it. I have it set up so that the local script waits for the HumanoidRootPart and then gets the Position, but that clearly doesn’t work sometimes.
Magnitude gets the Length of a Vector3, not a CFrame, so i dont understand why you are doing CFrame - CFrame which is an incorrect usage of CFrame, as its supposed to be Vector3 - Vector3, you can remove the usage of (Difference).Magnitude and replace it with DistanceFromCharacter, which does the exact same thing, here should also be a more “Organized” Approach with your code:
local arm = char:WaitForChild("fakeHand") -- gets arms prior to code
local t = 248 -- short for "tint", Institutional white's RGB code is "248"
local A0, A1 = Instance.new('Attachment'), Instance.new('Attachment') -- A Valid Syntax
A0.Parent = workspace.Terrain; A0.WorldPosition = mousepos -- Also a Valid Syntax
A1.Parent = arm -- Parents "A1"
local rope = Instance.new("RopeConstraint") -- rope
rope.Attachment0 = A0; rope.Attachment1 = A1 -- rope Attachment
rope.Visible = true; -- Visible rope
rope.Thickness = .1 -- Thickness of rope
rope.Color = Color3.fromRGB(t,t,t) -- Applies tint Color Code: (248, 248, 248)
rope.Parent = arm -- Parents Rope
rope.Length = player:DistanceFromCharacter(target.Position) -- Length of Vector3
I tried :DistanceFromCharacter and it still keeps throwing the error randomly. It works and then just doesn’t work, and that’s all that I can tell you, unfortunately, because that’s all I know.