function Player() local ray = Ray.new(Root.Parent.Head.Position,(Root.Parent.Head.CFrame.LookVector).unit*5000) local hit, position = game.Workspace:FindPartOnRay(ray) local playerList = game.Players:GetChildren() if hit ~= nil then local Thing = hit.Parent if Thing.ClassName ~= "Accessory" then for i, v in pairs(playerList) do local playerLST = playerList[i] print (playerLST) print (Thing.Name) if Thing.Name == playerLST then local distance = (hit.Position - Root.Parent.Head.Position).magnitude print(distance) end end end end end
function Player() local ray = Ray.new(Root.Parent.Head.Position,(Root.Parent.Head.CFrame.LookVector).unit*5000) local hit, position = game.Workspace:FindPartOnRay(ray) local playerList = game.Players:GetChildren() if hit ~= nil then local Thing = hit.Parent if Thing:IsA("Accoutrement") ~= true then for i, v in pairs(playerList) do local playerLST = v print (playerLST) print (Thing.Name) if Thing.Name == playerLST.Name then local distance = (hit.Position - Root.Parent.Head.Position).magnitude print(distance) end end end end end
You were trying to compare a String to an Object. The fix was simply to add a .Name after playerLST.
If this helped, make sure to upvote/accept it! Thanks!