okay so im stuck at finding out how to fix this error. Im making a distance tracker and it takes the lowest number there and changes the text to that number and puts the name of player thats close to the local player.
I have read on Most efficiently best way to get the smallest numeric value in a table while also taking its index?
to find the lowest number but I do not know how to do table.insert for it.
and kept getting errors such as invalid argument #3 (string expected, got nil)
heres my script
local StudsText = Frame.Studs
local RunService = game:GetService("RunService")
local player = game.Players.LocalPlayer
local character = player.Character
if not character or not character.Parent then
character = player.CharacterAdded:wait()
end
local otherplayers = game.Players:GetChildren()
local playertable = {}
local totaltable = #playertable
function getLowest()
local low = math.huge
local index
for i, v in pairs(playertable) do
if v < low then
low = v
index = i
end
end
return index
end
RunService.RenderStepped:Connect(function()
local playerpos = character.Head.Position
if #otherplayers > 0 then
for i,players in pairs(otherplayers) do
if players ~= player then
local othercharacter = players.Character
local otherplayerpos = players.Character.Head.Position
local studsX = (playerpos.X - otherplayerpos.X)
local studsZ = (playerpos.Z - otherplayerpos.Z)
local studs = studsX + studsZ
table.insert(playertable,totaltable+1,players.Name)
playertable[players.name] = studs
totaltable = totaltable + 1
end
end
StudsText.Text = getLowest()
end
end)