Hello I’ll cut right into the chase, I have this really weird table that prints the values when it’s index is always adding to itself by 1 but when it adds to itself by something more than 1 it always prints nil. I have tried to index using tonumber or tostring but none of those worked.
code (very messy):
local follow=false
local rs=game:GetService("RunService")
local noobhrp=workspace.Noob:FindFirstChild("HumanoidRootPart")
local plrhrp=game.Players.LocalPlayer.Character:FindFirstChild("HumanoidRootPart")
local positions={}
local parts={}
local partamount=0
rs.Stepped:Connect(function()
if follow==true then
table.insert(positions,plrhrp.CFrame)
for i,v in pairs(positions) do
partamount=i
end
end
end)
for i=1,partamount,1 do
if i>=20 then
local increment=0
local atinc=0
local p2=0 -- the index that im trying to use for parts table
repeat wait() p2=p2+2 atinc=atinc+1; increment=increment+20
p2=tostring(o2)
local twentypos=Instance.new("Part")
local b=Instance.new("Beam")
local a0=Instance.new("Attachment")
local a1=Instance.new("Attachment")
table.insert(parts, twentypos)
a0.Parent=twentypos
a0.Name="a0"
a1.Name="a1"
print(p2) -- this doesn't print
print(parts[p2]) -- this also doesn't print
print(tonumber(parts[p2]) -- neither does this
print(parts[atinc]) -- this prints and only this
b.Attachment0=a0
b.Attachment1=a1
b.Parent=twentypos
twentypos.Anchored=true
twentypos.Transparency=.8
twentypos.Material=Enum.Material.Neon
twentypos.CFrame=positions[increment]
twentypos.CanCollide=false
twentypos.Size=Vector3.new(2,2,1)
twentypos.Parent=workspace.PlayPos
until i==1
end
end
end
end)```
If you have any ideas on what I should do to fix this, please lmk in the comments :)