Creating a table to record characters past positions is not working

I would like to record past positions of a character with a table. However, I keep getting this error when trying to print the position table image

local RS = game:GetService("ReplicatedStorage")
local Run = game:GetService("RunService")
local plrs = game:GetService("Players")
local positions = nil
local Pos = {}

plrs.PlayerAdded:Connect(function(player)
	table.insert(Pos, 'checking')

end)

local function logPosition(plr)
	if plr:IsDescendantOf(workspace) then
		local curPos = plr:FindFirstChild("HumanoidRootPart").Position
		print(curPos)
		table.insert(Pos, curPos)
		print(table.getn(Pos))
		print(table.concat(Pos, "     "))
	end
end

while true and wait(2) do
	for i,v in pairs(plrs:GetChildren()) do
		plr = game:GetService("Workspace"):WaitForChild(v.Name)
		if table.getn(Pos)+1 <= 5 then
			logPosition(plr)
		else
			table.remove(Pos, 1)
		end
	end

end

You are passing in an empty string for the seperator so it goes reee. However you are making this too complicated for yourself, you can just use a stack data structure and have this be like 15 lines…

1 Like

I will give stack data structure a look, thank you!